Class: ActiveSupport::Cache::MongoDbStore

Inherits:
Store
  • Object
show all
Defined in:
lib/active_support/cache/mongo_db_store.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ MongoDbStore

Returns a new instance of MongoDbStore.



13
14
15
16
17
# File 'lib/active_support/cache/mongo_db_store.rb', line 13

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

Instance Attribute Details

#collection_nameObject (readonly)

Returns the value of attribute collection_name.



11
12
13
# File 'lib/active_support/cache/mongo_db_store.rb', line 11

def collection_name
  @collection_name
end

Instance Method Details

#cleanup(_) ⇒ Object



23
24
25
# File 'lib/active_support/cache/mongo_db_store.rb', line 23

def cleanup(_)
  collection.find(expires_at: {'$lt' => Time.now.utc.to_i}).delete_many
end

#clearObject



19
20
21
# File 'lib/active_support/cache/mongo_db_store.rb', line 19

def clear
  collection.find.delete_many
end

#delete_entry(key, _) ⇒ Object



34
35
36
# File 'lib/active_support/cache/mongo_db_store.rb', line 34

def delete_entry(key, _)
  collection.find(_id: key).delete_one
end

#delete_matched(matcher, options = nil) ⇒ Object

Parameters:

  • matcher (Regexp)
  • options (Hash) (defaults to: nil)


29
30
31
32
# File 'lib/active_support/cache/mongo_db_store.rb', line 29

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