Method: ActiveSupport::Cache::Store#read

Defined in:
lib/active_support/cache.rb

#read(name, options = nil) ⇒ Object

Fetches data from the cache, using the given key. If there is data in the cache with the given key, then that data is returned. Otherwise, nil is returned.

Options are passed to the underlying cache implementation.



312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
# File 'lib/active_support/cache.rb', line 312

def read(name, options = nil)
  options = merged_options(options)
  key = namespaced_key(name, options)
  instrument(:read, name, options) do |payload|
    entry = read_entry(key, options)
    if entry
      if entry.expired?
        delete_entry(key, options)
        payload[:hit] = false if payload
        nil
      else
        payload[:hit] = true if payload
        entry.value
      end
    else
      payload[:hit] = false if payload
      nil
    end
  end
end