Class: RailsCachedMethod::CachedProxy
- Inherits:
-
Object
- Object
- RailsCachedMethod::CachedProxy
- Defined in:
- lib/rails_cached_method.rb
Instance Method Summary collapse
- #__value__ ⇒ Object
-
#initialize(object, key: nil, expires_in:, parent_key: nil, recache: false) ⇒ CachedProxy
constructor
A new instance of CachedProxy.
- #method_missing(*args) ⇒ Object
Constructor Details
#initialize(object, key: nil, expires_in:, parent_key: nil, recache: false) ⇒ CachedProxy
Returns a new instance of CachedProxy.
14 15 16 17 18 19 20 21 |
# File 'lib/rails_cached_method.rb', line 14 def initialize(object, key: nil, expires_in:, parent_key: nil, recache: false) @__object__ = object @__key__ = key @__expires_in__ = expires_in @__recache__ = recache @__parent_key__ = parent_key @__object__ end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(*args) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/rails_cached_method.rb', line 27 def method_missing(*args) key = ___compose_key__(args) if @__recache__ #puts "deleting: #{key}" Rails.cache.delete(key) end #puts "key: #{key}, expires_in: #{@__expires_in__}, args: #{args}, recache: #{@__recache__}" Rails.cache.fetch(key, expires_in: @__expires_in__) do CachedProxy.new( @__object__.send(*args), expires_in: @__expires_in__, recache: @__recache__, parent_key: key, ) end end |
Instance Method Details
#__value__ ⇒ Object
23 24 25 |
# File 'lib/rails_cached_method.rb', line 23 def __value__ @__object__ end |