Class: Faraday::HttpCache::Storage

Inherits:
Object
  • Object
show all
Defined in:
lib/translation_cms/hooks/storage.rb

Instance Method Summary collapse

Instance Method Details

#read(request, klass = Faraday::HttpCache::Response) ⇒ Object

Internal: Reads a key based on the given request from the underlying cache.

request - The Hash containing the request information.

:method          - The HTTP Method used for the request.
:url             - The requested URL.
:request_headers - The custom headers for the request.

klass - The Class to be instantiated with the recovered informations.



15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/translation_cms/hooks/storage.rb', line 15

def read(request, klass = Faraday::HttpCache::Response)
  cache_key = cache_key_for(request)
  found = @cache.read(cache_key)

  if found
    # payload = @serializer.load(found).each_with_object({}) do |(key,value), hash|
    #   hash[key.to_sym] = value
    # end
    payload = MultiJson.load(found).deep_symbolize_keys

    klass.new(payload)
  end
end