Module: ArtirixCacheService::ViewHelper

Defined in:
lib/artirix_cache_service/view_helper.rb

Instance Method Summary collapse

Instance Method Details

#artirix_cache(key_prefix, options_name = [], *key_params, &block) ⇒ Object

Raises:

  • (ArgumentError)


4
5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/artirix_cache_service/view_helper.rb', line 4

def artirix_cache(key_prefix, options_name = [], *key_params, &block)
  raise ArgumentError, 'key_prefix is required' unless key_prefix.present?

  options = ArtirixCacheService.options *Array(options_name),
                                        return_if_missing: :default

  # if `disable_cache` in the options -> yield without caching
  if options[:disable_cache]
    yield
  else
    key = ArtirixCacheService.key key_prefix, *key_params
    cache(key, options, &block)
  end
end