Module: CacheFinder::Container
Overview
Will cached everything placed in a block.
Example of using:
Company.cache_container(key: :companies) { Company.all }
Included in a module, the cache_container method will automatically add a Class_name to the key of the cache. In this way the key will be:
['Class_name', key]
You can use container standalone, example of using:
CacheFinder::Container.cache(key: [:company, :name]) { 'Microsoft' }
Class Method Summary collapse
-
.cache(options, &block) ⇒ Object
CacheFinder::Container.cache.
Instance Method Summary collapse
Methods included from Helper
Class Method Details
.cache(options, &block) ⇒ Object
CacheFinder::Container.cache
41 42 43 44 |
# File 'lib/cache_finder/finder/container.rb', line 41 def cache(, &block) key = [:key] Rails.cache.fetch(key) { block.call } end |
Instance Method Details
#cache_container(options, &block) ⇒ Object
35 36 37 38 |
# File 'lib/cache_finder/finder/container.rb', line 35 def cache_container(, &block) key = cache_container_key?([:key]) Rails.cache.fetch(key) { block.call } end |