Class: Faraday::Cache

Inherits:
Object
  • Object
show all
Defined in:
lib/faraday/cache.rb

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ Cache

Returns a new instance of Cache.



6
7
8
# File 'lib/faraday/cache.rb', line 6

def initialize(app)
  @app = app
end

Instance Method Details

#call(env) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/faraday/cache.rb', line 14

def call(env)
  @url = env[:url]

  @website_id = env[:request_headers]['x-reviewed-website']

  if serve_from_cache && store.exist?(cache_key)
    Hashie::Mash.new(Marshal.load( store.read(cache_key) ))
  else
    @app.call(env).on_complete do |response|
      if store_response
        store.delete(cache_key)
        store.write(cache_key, Marshal.dump(response), write_options)
      end
    end
  end
end

#storeObject



10
11
12
# File 'lib/faraday/cache.rb', line 10

def store
  Reviewed::Cache.store
end