Sha256: 22a0d1fb39c349aa2a045c24aed89c02d3d04f46d0ba674f899cf643fcd4a841
Contents?: true
Size: 1.33 KB
Versions: 1
Compression:
Stored size: 1.33 KB
Contents
require 'mongoid' require 'active_support' module ActiveSupport module Cache class MongoidStore < Store attr_reader :collection_name def initialize(options = {}) @collection_name = options[:collection] || :cache options[:expires_in] ||= 1.hour super(options) end def clear(options = nil) collection.find.remove_all end def cleanup(options = nil) options = merged_options(options) collection.find(expires_at: {'$lt' => Time.now.utc.to_i}).remove_all end def delete_matched(matcher, options = nil) options = merged_options(options) collection.find(_id: key_matcher(matcher, options)).remove_all end protected def write_entry(key, entry, options) collection.find(_id: key).upsert(_id: key, value: entry.value, expires_at: entry.expires_at.to_i, created_at: Time.now.utc.to_i) end def read_entry(key, options = nil) document = collection.find(_id: key, expires_at: {'$gt' => Time.now.utc.to_i}).first ActiveSupport::Cache::Entry.new(document['value']) if document end def delete_entry(key, options = nil) collection.find(_id: key).remove end private def collection Mongoid.session(:default)[collection_name] end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
mongoid_store-0.0.1 | lib/active_support/cache/mongoid_store.rb |