Class: MongoStore::Cache
- Inherits:
-
ActiveSupport::Cache::Store
- Object
- ActiveSupport::Cache::Store
- MongoStore::Cache
- Defined in:
- lib/mongo_store/cache.rb
Instance Attribute Summary collapse
-
#collection ⇒ Object
readonly
Returns the value of attribute collection.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
- #clear(options = nil) ⇒ Object
-
#delete_entry(key, options) ⇒ Object
we don’t get any info from mongo driver if delete actually deleted anything.
- #expires_in ⇒ Object
-
#initialize(collection, options = {}) ⇒ Cache
constructor
A new instance of Cache.
- #read_entry(key, options) ⇒ Object
- #write_entry(key, entry, options) ⇒ Object
Constructor Details
#initialize(collection, options = {}) ⇒ Cache
Returns a new instance of Cache.
26 27 28 |
# File 'lib/mongo_store/cache.rb', line 26 def initialize(collection, ={}) @collection, = collection, || {} end |
Instance Attribute Details
#collection ⇒ Object (readonly)
Returns the value of attribute collection.
24 25 26 |
# File 'lib/mongo_store/cache.rb', line 24 def collection @collection end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
24 25 26 |
# File 'lib/mongo_store/cache.rb', line 24 def end |
Instance Method Details
#clear(options = nil) ⇒ Object
52 53 54 |
# File 'lib/mongo_store/cache.rb', line 52 def clear(=nil) rescue_connection_failure { @collection.remove } end |
#delete_entry(key, options) ⇒ Object
we don’t get any info from mongo driver if delete actually deleted anything. this will always return true.
47 48 49 50 |
# File 'lib/mongo_store/cache.rb', line 47 def delete_entry(key, ) rescue_connection_failure { @collection.remove({:_id => key.to_s}) } true end |
#expires_in ⇒ Object
30 31 32 |
# File 'lib/mongo_store/cache.rb', line 30 def expires_in @expires_in ||= [:expires_in] || 1.month end |
#read_entry(key, options) ⇒ Object
40 41 42 43 44 |
# File 'lib/mongo_store/cache.rb', line 40 def read_entry(key, ) entry = nil rescue_connection_failure { entry = @collection.find_one(:_id => key.to_s) } entry ? Marshal.load(entry['value'].to_s) : nil end |
#write_entry(key, entry, options) ⇒ Object
34 35 36 37 38 |
# File 'lib/mongo_store/cache.rb', line 34 def write_entry(key, entry, ) doc = {:_id => key.to_s, :value => BSON::Binary.new(Marshal.dump(entry))} rescue_connection_failure { @collection.save(doc) } true end |