Module: ActiveSupport::Cache::MongoCacheStore::Backend::Base
- Defined in:
- lib/active_support/cache/mongo_cache_store/backend/base.rb
Overview
Base methods used by all MongoCacheStore backends
Instance Method Summary collapse
- #decrement(name, amount = 1, options = {}) ⇒ Object
- #delete_matched(matcher, options = nil) ⇒ Object
- #increment(name, amount = 1, options = {}) ⇒ Object
- #read_multi(*names) ⇒ Object
Instance Method Details
#decrement(name, amount = 1, options = {}) ⇒ Object
15 16 17 |
# File 'lib/active_support/cache/mongo_cache_store/backend/base.rb', line 15 def decrement(name, amount = 1, = {}) write_counter(name,amount.to_i*-1,) end |
#delete_matched(matcher, options = nil) ⇒ Object
49 50 51 52 53 54 |
# File 'lib/active_support/cache/mongo_cache_store/backend/base.rb', line 49 def delete_matched(matcher, = nil) col = get_collection() safe_rescue do col.remove({'_id' => matcher}) end end |
#increment(name, amount = 1, options = {}) ⇒ Object
11 12 13 |
# File 'lib/active_support/cache/mongo_cache_store/backend/base.rb', line 11 def increment(name, amount = 1, = {}) write_counter(name,amount.to_i,) end |
#read_multi(*names) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/active_support/cache/mongo_cache_store/backend/base.rb', line 19 def read_multi(*names) = names. = () results = {} col = get_collection() key_map = names.inject({}) do |h, name| h[namespaced_key(name,)] = name h end safe_rescue do query = { :_id => { '$in' => key_map.keys}, :expires_at => { '$gt' => Time.now } } col.find(query) do |cursor| cursor.each do |r| results[key_map[r['_id']]] = inflate_entry(r).value end end end results end |