Module: ActiveSupport::Cache::MongoCacheStore::Backend::Base

Included in:
Capped, MultiTTL, Standard, TTL
Defined in:
lib/active_support/cache/mongo_cache_store/backend/base.rb

Overview

Base methods used by all MongoCacheStore backends

Instance Method Summary collapse

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, options = {})
  write_counter(name,amount.to_i*-1,options)
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, options = nil)
  col = get_collection(options)
  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, options = {})
  write_counter(name,amount.to_i,options)
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)
  options = names.extract_options!
  options = merged_options(options)
  results = {}

  col = get_collection(options)

  key_map = names.inject({}) do |h, name|
    h[namespaced_key(name,options)] = 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