Class: CacheKeeper::CachedMethod
- Inherits:
-
Object
- Object
- CacheKeeper::CachedMethod
- Includes:
- Refreshable
- Defined in:
- app/models/cache_keeper/cached_method.rb
Defined Under Namespace
Modules: Refreshable
Instance Attribute Summary collapse
-
#klass ⇒ Object
Returns the value of attribute klass.
-
#method_name ⇒ Object
Returns the value of attribute method_name.
-
#options ⇒ Object
Returns the value of attribute options.
Instance Method Summary collapse
- #alias_for_original_method ⇒ Object
- #call(instance) ⇒ Object
-
#initialize(klass, method_name, options = {}) ⇒ CachedMethod
constructor
A new instance of CachedMethod.
Methods included from Refreshable
Constructor Details
#initialize(klass, method_name, options = {}) ⇒ CachedMethod
Returns a new instance of CachedMethod.
6 7 8 9 10 |
# File 'app/models/cache_keeper/cached_method.rb', line 6 def initialize(klass, method_name, = {}) self.klass = klass self.method_name = method_name self. = .with_indifferent_access end |
Instance Attribute Details
#klass ⇒ Object
Returns the value of attribute klass.
4 5 6 |
# File 'app/models/cache_keeper/cached_method.rb', line 4 def klass @klass end |
#method_name ⇒ Object
Returns the value of attribute method_name.
4 5 6 |
# File 'app/models/cache_keeper/cached_method.rb', line 4 def method_name @method_name end |
#options ⇒ Object
Returns the value of attribute options.
4 5 6 |
# File 'app/models/cache_keeper/cached_method.rb', line 4 def end |
Instance Method Details
#alias_for_original_method ⇒ Object
12 13 14 |
# File 'app/models/cache_keeper/cached_method.rb', line 12 def alias_for_original_method :"__#{method_name}__hooked__" end |
#call(instance) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'app/models/cache_keeper/cached_method.rb', line 16 def call(instance) if cache_entry.blank? refresh instance elsif cache_entry.expired? if must_revalidate? refresh instance else refresh_later instance cache_entry.value end else cache_entry.value end end |