Module: Perforated::Compatibility

Defined in:
lib/perforated/compatibility/fetch_multi.rb

Class Method Summary collapse

Class Method Details

.custom_fetch_multi(*names) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/perforated/compatibility/fetch_multi.rb', line 13

def self.custom_fetch_multi(*names)
  options = names.extract_options!
  results = Perforated.cache.read_multi(*names, options)

  names.each_with_object({}) do |(name, _), memo|
    memo[name] = results.fetch(name) do
      value = yield name
      Perforated.cache.write(name, value, options)
      value
    end
  end
end

.fetch_multi(*names, &block) ⇒ Object



5
6
7
8
9
10
11
# File 'lib/perforated/compatibility/fetch_multi.rb', line 5

def self.fetch_multi(*names, &block)
  if supports_fetch_multi?
    Perforated.cache.fetch_multi(*names, &block)
  else
    custom_fetch_multi(*names, &block)
  end
end

.supports_fetch_multi?Boolean

Returns:

  • (Boolean)


26
27
28
29
30
31
32
33
# File 'lib/perforated/compatibility/fetch_multi.rb', line 26

def self.supports_fetch_multi?
  cache = Perforated.cache

  cache.respond_to?(:fetch_multi) && !(
    cache.instance_of?(ActiveSupport::Cache::MemoryStore) ||
    cache.instance_of?(ActiveSupport::Cache::NullStore)
  )
end