Class: Faraday::ManualCache
- Inherits:
-
Middleware
- Object
- Middleware
- Faraday::ManualCache
- Defined in:
- lib/faraday/manual_cache.rb
Overview
Middleware for caching Faraday responses based on a specified expiry.
As with faraday-http-cache, it’s recommended that this middleware be added fairly low in the middleware stack.
Currently accepts four arguments:
:conditions - Conditional caching based on a lambda (default: GET/HEAD
requests)
:expires_in - Cache expiry, in seconds (default: 30).
:logger - A logger object to send cache hit/miss/write messages.
Constant Summary collapse
- DEFAULT_CONDITIONS =
->(env) { env.method == :get || env.method == :head }
- DEFAULT_CACHE_KEY =
->(env) { env.url }
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, *args) ⇒ ManualCache
constructor
A new instance of ManualCache.
Constructor Details
#initialize(app, *args) ⇒ ManualCache
Returns a new instance of ManualCache.
21 22 23 24 25 26 27 28 |
# File 'lib/faraday/manual_cache.rb', line 21 def initialize(app, *args) super(app) = args.first || {} @conditions = .fetch(:conditions, DEFAULT_CONDITIONS) @expires_in = .fetch(:expires_in, 30) @logger = .fetch(:logger, nil) @cache_key = .fetch(:cache_key, DEFAULT_CACHE_KEY) end |
Instance Method Details
#call(env) ⇒ Object
30 31 32 |
# File 'lib/faraday/manual_cache.rb', line 30 def call(env) dup.call!(env) end |