Module: Delorean::Cache
- Defined in:
- lib/delorean/cache.rb,
lib/delorean/cache/adapters.rb,
lib/delorean/cache/adapters/base.rb,
lib/delorean/cache/adapters/ruby_cache.rb more...
Defined Under Namespace
Modules: Adapters
Constant Summary collapse
- NODE_CACHE_DEFAULT_CALLBACK =
lambda do |klass:, method:, params:| { cache: true, } end
Class Attribute Summary collapse
-
.adapter ⇒ Object
Returns the value of attribute adapter.
-
.node_cache_callback ⇒ Object
Returns the value of attribute node_cache_callback.
Class Method Summary collapse
Class Attribute Details
permalink .adapter ⇒ Object
Returns the value of attribute adapter.
14 15 16 |
# File 'lib/delorean/cache.rb', line 14 def adapter @adapter end |
permalink .node_cache_callback ⇒ Object
Returns the value of attribute node_cache_callback.
50 51 52 |
# File 'lib/delorean/cache.rb', line 50 def node_cache_callback @node_cache_callback end |
Class Method Details
permalink .with_cache(klass:, method:, mutable_params:, params:) ⇒ Object
[View source]
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/delorean/cache.rb', line 16 def with_cache(klass:, method:, mutable_params:, params:) delorean_cache_adapter = ::Delorean::Cache.adapter klass_name = "#{klass.name}#{::Delorean::POST}" = node_cache_callback.call( klass: klass, method: method, params: mutable_params ) return yield unless [:cache] cache_key = delorean_cache_adapter.cache_key( klass: klass_name, method_name: method, args: [params] ) cached_item = delorean_cache_adapter.fetch_item( klass: klass_name, cache_key: cache_key, default: :NF ) return cached_item if cached_item != :NF res = yield delorean_cache_adapter.cache_item( klass: klass_name, cache_key: cache_key, item: res, ) res end |