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