Module: AnyCache::Patches::DalliStore::ActiveSupportFetchWithKey Private

Defined in:
lib/any_cache/patches/dalli_store.rb

Overview

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

Since:

  • 0.3.1

API:

  • private

Instance Method Summary collapse

Instance Method Details

#fetch(name, options = nil) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

NOTE: original fetch implementation with my own little fix (see #43 line of code below) rubocop:disable all

Since:

  • 0.3.1

API:

  • private



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/any_cache/patches/dalli_store.rb', line 24

def fetch(name, options=nil)
  options ||= {}
  options[:cache_nils] = true if @options[:cache_nils]
  namespaced_name = namespaced_key(name, options)
  not_found = options[:cache_nils] ? Dalli::Server::NOT_FOUND : nil
  if block_given?
    entry = not_found
    unless options[:force]
      entry = instrument_with_log(:read, namespaced_name, options) do |payload|
        read_entry(namespaced_name, options).tap do |result|
          if payload
            payload[:super_operation] = :fetch
            payload[:hit] = not_found != result
          end
        end
      end
    end

    if not_found == entry
      result = instrument_with_log(:generate, namespaced_name, options) do |payload|
        # FIX: https://github.com/petergoldstein/dalli/pull/701
        yield(name)
        # FIX: https://github.com/petergoldstein/dalli/pull/701
      end
      write(name, result, options)
      result
    else
      instrument_with_log(:fetch_hit, namespaced_name, options) { |payload| }
      entry
    end
  else
    read(name, options)
  end
end