Class: Faraday::Cache
- Inherits:
-
Object
- Object
- Faraday::Cache
- Defined in:
- lib/faraday/cache.rb
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app) ⇒ Cache
constructor
A new instance of Cache.
- #store ⇒ Object
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 30 31 32 33 34 |
# 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) begin Hashie::Mash.new(MultiJson.load( store.read(cache_key) )) rescue => e raise e. + ": #{cache_key}" end else @app.call(env).on_complete do |response| if store_response?(response) store.delete(cache_key) storeable_response = MultiJson.dump(response.slice(:status, :body, :response_headers)) store.write(cache_key, storeable_response, ) end end end end |
#store ⇒ Object
10 11 12 |
# File 'lib/faraday/cache.rb', line 10 def store Reviewed::Cache.store end |