Class: ActiveRecord::Base

Inherits:
Object show all
Includes:
Cachetastic::Cacheable
Defined in:
lib/gems/cachetastic-2.1.2/lib/cachetastic/rails_extensions/active_record_base.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Cachetastic::Cacheable

#cache_self, included, #uncache_self

Class Method Details

.get_from_cache(key, self_populate = false) ⇒ Object

Returns an object from the cache for a given key. If the object returned is nil and the self_populate parameter is true then the key will be used to try and find the object in the database, set the object into the cache, and then return the object.



13
14
15
16
17
18
19
20
21
22
# File 'lib/gems/cachetastic-2.1.2/lib/cachetastic/rails_extensions/active_record_base.rb', line 13

def self.get_from_cache(key, self_populate = false)
  res = cache_class.get(key)
  if res.nil? && self_populate
    res = self.name.constantize.find(key)
    unless res.nil?
      res.cache_self
    end
  end
  res
end

Instance Method Details

#cachetastic_keyObject



5
6
7
# File 'lib/gems/cachetastic-2.1.2/lib/cachetastic/rails_extensions/active_record_base.rb', line 5

def cachetastic_key
  self.id
end