Module: Cardiac::Model::CacheDecoration::ClassMethods
- Defined in:
- lib/cardiac/model/cache_decoration.rb
Constant Summary collapse
- MODEL_CACHE_CONTROL_PROC =
The callback to be installed on the adapter.
Proc.new{|adapter| adapter.klass._model_cache_control(adapter.response) }
Instance Method Summary collapse
-
#_model_cache_control(response) ⇒ Object
Internal method that controls the model cache, using the given response object.
-
#cache_all!(options = {}) ⇒ Object
Causes all find(..) methods to go through an object-level cache, which is populated on demand whenever it is needed.
Instance Method Details
#_model_cache_control(response) ⇒ Object
Internal method that controls the model cache, using the given response object.
28 29 30 31 32 33 34 35 |
# File 'lib/cardiac/model/cache_decoration.rb', line 28 def _model_cache_control(response) response = Rack::Cache::Response.new(*response.to_a) if response.fresh? @_model_cache_control[:expires_at] = response.expires || (response.date + response.ttl) else @_model_cache_control[:expires_at] = Time.now end end |
#cache_all!(options = {}) ⇒ Object
Causes all find(..) methods to go through an object-level cache, which is populated on demand whenever it is needed.
Pass false
to uninstall the model cache.
17 18 19 20 21 22 23 24 25 |
# File 'lib/cardiac/model/cache_decoration.rb', line 17 def cache_all! ={} if @_model_cache_control = (Hash=== ? : {}).update(expires_at: Time.now) __operation_proxy__.__adapter__.after_execute MODEL_CACHE_CONTROL_PROC else @model_cache = @_model_cache_control = nil __operation_proxy__.__adapter__.skip_callback :execute, :after, MODEL_CACHE_CONTROL_PROC end end |