Class: ActiveSupport::Cache::MongoidStore

Inherits:
Store
  • Object
show all
Defined in:
lib/active_support/cache/mongoid-store.rb,
lib/active_support/cache/mongoid_store.rb

Defined Under Namespace

Classes: Entry

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ MongoidStore

Returns a new instance of MongoidStore.



11
12
13
14
15
# File 'lib/active_support/cache/mongoid-store.rb', line 11

def initialize(options = {})
  @collection_name = options[:collection] || :rails_cache
  options[:expires_in] ||= 1.hour
  super(options)
end

Instance Attribute Details

#collection_nameObject (readonly)

Returns the value of attribute collection_name.



9
10
11
# File 'lib/active_support/cache/mongoid-store.rb', line 9

def collection_name
  @collection_name
end

Instance Method Details

#cleanup(options = nil) ⇒ Object



21
22
23
24
# File 'lib/active_support/cache/mongoid-store.rb', line 21

def cleanup(options = nil)
  options = merged_options(options)
  collection.find(expires_at: {'$lt' => Time.now.utc.to_i}).remove_all
end

#clear(options = nil) ⇒ Object



17
18
19
# File 'lib/active_support/cache/mongoid-store.rb', line 17

def clear(options = nil)
  collection.find.remove_all
end

#delete_entry(key, options = nil) ⇒ Object



31
32
33
# File 'lib/active_support/cache/mongoid-store.rb', line 31

def delete_entry(key, options = nil)
  collection.find(_id: key).remove
end

#delete_matched(matcher, options = nil) ⇒ Object



26
27
28
29
# File 'lib/active_support/cache/mongoid-store.rb', line 26

def delete_matched(matcher, options = nil)
  options = merged_options(options)
  collection.find(_id: key_matcher(matcher, options)).remove_all
end