Module: Perforated::Compatibility
- Defined in:
- lib/perforated/compatibility/fetch_multi.rb
Class Method Summary collapse
- .custom_fetch_multi(*names) ⇒ Object
- .fetch_multi(*names, &block) ⇒ Object
- .supports_fetch_multi? ⇒ Boolean
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) = names. results = Perforated.cache.read_multi(*names, ) names.each_with_object({}) do |(name, _), memo| memo[name] = results.fetch(name) do value = yield name Perforated.cache.write(name, value, ) 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
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 |