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
-
#autorefresh_block ⇒ Object
Returns the value of attribute autorefresh_block.
-
#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 = {}, &block) ⇒ CachedMethod
constructor
A new instance of CachedMethod.
- #stale?(target) ⇒ Boolean
Methods included from SerializableTarget
#serialize_target, #serialize_target?
Methods included from Refreshable
#autorefresh, #refresh, #refresh_later
Constructor Details
#initialize(klass, method_name, options = {}, &block) ⇒ CachedMethod
Returns a new instance of CachedMethod.
7 8 9 10 11 12 |
# File 'app/models/cache_keeper/cached_method.rb', line 7 def initialize(klass, method_name, = {}, &block) self.klass = klass self.method_name = method_name self. = .with_indifferent_access self.autorefresh_block = block end |
Instance Attribute Details
#autorefresh_block ⇒ Object
Returns the value of attribute autorefresh_block.
5 6 7 |
# File 'app/models/cache_keeper/cached_method.rb', line 5 def autorefresh_block @autorefresh_block end |
#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 @options end |
Instance Method Details
#alias_for_original_method ⇒ Object
14 15 16 |
# File 'app/models/cache_keeper/cached_method.rb', line 14 def alias_for_original_method :"__#{method_name}__hooked__" end |
#call(target) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'app/models/cache_keeper/cached_method.rb', line 22 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 |
#stale?(target) ⇒ Boolean
18 19 20 |
# File 'app/models/cache_keeper/cached_method.rb', line 18 def stale?(target) cache_entry(target).blank? || cache_entry(target).expired? end |