Class: VinExploder::Cache::EMSynchronyCouchDBCacheStore
- Defined in:
- lib/vin_exploder/cache/em_synchrony_couchdb_cache_store.rb
Instance Attribute Summary
Attributes inherited from Store
Instance Method Summary collapse
- #delete(vin) ⇒ Object
-
#initialize(options = {}) ⇒ EMSynchronyCouchDBCacheStore
constructor
A new instance of EMSynchronyCouchDBCacheStore.
- #read(vin) ⇒ Object
- #write(vin, hash) ⇒ Object
Methods inherited from Store
Constructor Details
#initialize(options = {}) ⇒ EMSynchronyCouchDBCacheStore
Returns a new instance of EMSynchronyCouchDBCacheStore.
7 8 9 10 11 12 |
# File 'lib/vin_exploder/cache/em_synchrony_couchdb_cache_store.rb', line 7 def initialize(={}) @db_name = .delete(:db_name) @db = EM::Synchrony::CouchDB.new @db.create_db(@db_name) unless @db.get_all_dbs.include?(@db_name) end |
Instance Method Details
#delete(vin) ⇒ Object
28 29 30 31 32 |
# File 'lib/vin_exploder/cache/em_synchrony_couchdb_cache_store.rb', line 28 def delete(vin) key = make_vin_cache_key(vin) result = @db.delete(@db_name, @db.get(@db_name, key)) !result.nil? && result['ok'] end |
#read(vin) ⇒ Object
14 15 16 17 18 19 20 |
# File 'lib/vin_exploder/cache/em_synchrony_couchdb_cache_store.rb', line 14 def read(vin) key = make_vin_cache_key(vin) result = @db.get(@db_name, key)['data'] symbolize_result_hash(result) rescue nil end |
#write(vin, hash) ⇒ Object
22 23 24 25 26 |
# File 'lib/vin_exploder/cache/em_synchrony_couchdb_cache_store.rb', line 22 def write(vin, hash) key = make_vin_cache_key(vin) @db.save(@db_name, "_id" => key, :data => hash) hash end |