Module: CacheFinder::Container

Includes:
Helper
Included in:
Finder::Singleton
Defined in:
lib/cache_finder/finder/container.rb

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

Instance Method Summary collapse

Methods included from Helper

#cache_container_key?

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(options, &block)
  key = options[: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(options, &block)
  key = cache_container_key?(options[:key])
  Rails.cache.fetch(key) { block.call }
end