Module: Rooftop::Rails::ObjectCache

Defined in:
app/models/concerns/rooftop/rails/object_cache.rb

Overview

This mixin adds object caching when you call find(). It overloads the find() method to cache the result, and read that instead if possible.

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



5
6
7
# File 'app/models/concerns/rooftop/rails/object_cache.rb', line 5

def self.included(base)
  base.extend(ClassMethods)
end

Instance Method Details

#cache_keyObject

Utility method to get the cache key for the instance.



10
11
12
# File 'app/models/concerns/rooftop/rails/object_cache.rb', line 10

def cache_key
  "#{self.class.cache_key_base}/#{self.id}"
end

#expire_cache!Object Also known as: expire!



14
15
16
# File 'app/models/concerns/rooftop/rails/object_cache.rb', line 14

def expire_cache!
  self.class.send(:expire_cache_for, self.id)
end