Class: Cachetastic::Adapters::Mongoid
- Defined in:
- lib/cachetastic/adapters/mongoid.rb
Defined Under Namespace
Classes: Store
Instance Attribute Summary collapse
-
#klass ⇒ Object
Returns the value of attribute klass.
Instance Method Summary collapse
-
#delete(key) ⇒ Object
set.
-
#expire_all ⇒ Object
delete.
-
#get(key) ⇒ Object
:nodoc:.
-
#initialize(klass) ⇒ Mongoid
constructor
A new instance of Mongoid.
-
#set(key, value, expiry_time = configatron.cachetastic.defaults.default_expiry) ⇒ Object
get.
-
#transform_key(key) ⇒ Object
expire_all.
Methods inherited from Base
#debug?, #marshal, #unmarshal, #valid?
Constructor Details
#initialize(klass) ⇒ Mongoid
Returns a new instance of Mongoid.
24 25 26 27 |
# File 'lib/cachetastic/adapters/mongoid.rb', line 24 def initialize(klass) self.klass = klass super end |
Instance Attribute Details
#klass ⇒ Object
Returns the value of attribute klass.
22 23 24 |
# File 'lib/cachetastic/adapters/mongoid.rb', line 22 def klass @klass end |
Instance Method Details
#delete(key) ⇒ Object
set
46 47 48 49 50 51 52 |
# File 'lib/cachetastic/adapters/mongoid.rb', line 46 def delete(key) # :nodoc: obj = connection.where(key: key).first if obj obj.destroy end return nil end |
#expire_all ⇒ Object
delete
54 55 56 57 |
# File 'lib/cachetastic/adapters/mongoid.rb', line 54 def expire_all # :nodoc: connection.destroy_all return nil end |
#get(key) ⇒ Object
:nodoc:
29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/cachetastic/adapters/mongoid.rb', line 29 def get(key) # :nodoc: obj = connection.where(key: key).first if obj if obj.expiry_time > Time.now return obj.value else obj.destroy end end return nil end |
#set(key, value, expiry_time = configatron.cachetastic.defaults.default_expiry) ⇒ Object
get
41 42 43 44 |
# File 'lib/cachetastic/adapters/mongoid.rb', line 41 def set(key, value, expiry_time = configatron.cachetastic.defaults.default_expiry) # :nodoc: Cachetastic::Adapters::Mongoid::Store.create!(cache_class: self.klass.name, key: key, value: value, expiry_time: expiry_time.from_now) return value end |
#transform_key(key) ⇒ Object
expire_all
59 60 61 |
# File 'lib/cachetastic/adapters/mongoid.rb', line 59 def transform_key(key) # :nodoc: key.to_s.hexdigest end |