Module: MongoStore::Cache::Rails2
- Defined in:
- lib/active_support/cache/mongo_store.rb
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
-
#delete(key, local_options = nil) ⇒ Object
Takes the specified value out of the collection.
-
#delete_matched(key, local_options = nil) ⇒ Object
Takes the value matching the pattern out of the collection.
-
#read(key, local_options = nil) ⇒ Object
Reads the value from the cache collection.
-
#write(key, value, local_options = nil) ⇒ Object
Inserts the value into the cache collection or updates the existing value.
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
7 8 9 |
# File 'lib/active_support/cache/mongo_store.rb', line 7 def @options end |
Instance Method Details
#delete(key, local_options = nil) ⇒ Object
Takes the specified value out of the collection.
29 30 31 32 33 |
# File 'lib/active_support/cache/mongo_store.rb', line 29 def delete(key, =nil) super opts = ? .merge() : collection.remove({'_id' => namespaced_key(key,opts)}) end |
#delete_matched(key, local_options = nil) ⇒ Object
Takes the value matching the pattern out of the collection.
37 38 39 40 41 |
# File 'lib/active_support/cache/mongo_store.rb', line 37 def delete_matched(key, =nil) super opts = ? .merge() : collection.remove({'_id' => key_matcher(key,opts)}) end |
#read(key, local_options = nil) ⇒ Object
Reads the value from the cache collection.
20 21 22 23 24 25 26 |
# File 'lib/active_support/cache/mongo_store.rb', line 20 def read(key, =nil) super opts = ? .merge() : if doc = collection.find_one('_id' => namespaced_key(key, opts), 'expires' => {'$gt' => Time.now}) doc['value'] end end |
#write(key, value, local_options = nil) ⇒ Object
Inserts the value into the cache collection or updates the existing value. The value must be a valid MongoDB type. An :expires_in option may be provided, as with MemCacheStore. If one is not provided, a default expiration of 1 day is used.
12 13 14 15 16 17 |
# File 'lib/active_support/cache/mongo_store.rb', line 12 def write(key, value, =nil) super opts = ? .merge() : expires = Time.now + opts[:expires_in] collection.update({'_id' => namespaced_key(key, opts)}, {'$set' => {'value' => value, 'expires' => expires}}, :upsert => true) end |