class ActiveSupport::Cache::MongoidStore
Attributes
collection_name[R]
Public Class Methods
new(options = {})
click to toggle source
Calls superclass method
# 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
Public Instance Methods
cleanup(options = nil)
click to toggle source
# 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)
click to toggle source
# File lib/active_support/cache/mongoid-store.rb, line 17 def clear(options = nil) collection.find.remove_all end
delete_entry(key, options = nil)
click to toggle source
# 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)
click to toggle source
# 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
Protected Instance Methods
read_entry(key, options = {})
click to toggle source
# File lib/active_support/cache/mongoid-store.rb, line 47 def read_entry(key, options = {}) expires_at = Time.now.utc.to_i doc = collection.find(_id: key, expires_at: {'$gt' => expires_at}).first Entry.for(doc) if doc end
write_entry(key, entry, options)
click to toggle source
# File lib/active_support/cache/mongoid-store.rb, line 37 def write_entry(key, entry, options) data = Entry.data_for(entry) expires_at = entry.expires_at.to_i created_at = Time.now.utc.to_i collection.find(_id: key).upsert(_id: key, data: data, expires_at: expires_at, created_at: created_at) entry end
Private Instance Methods
collection()
click to toggle source
# File lib/active_support/cache/mongoid-store.rb, line 139 def collection Mongoid.session(:default)[collection_name] end