Method: Faraday::HttpCache#initialize
- Defined in:
- lib/faraday/http_cache.rb
#initialize(app, options = {}) ⇒ HttpCache
Public: Initializes a new HttpCache middleware.
app - the next endpoint on the ‘Faraday’ stack. :store - A cache store that should respond to ‘read’, ‘write’, and ‘delete’. :serializer - A serializer that should respond to ‘dump’ and ‘load’. :shared_cache - A flag to mark the middleware as a shared cache or not. :instrumenter - An instrumentation object that should respond to ‘instrument’. :instrument_name - The String name of the instrument being reported on (optional). :logger - A logger object.
Examples:
# Initialize the middleware with a logger.
Faraday::HttpCache.new(app, logger: my_logger)
# Initialize the middleware with a logger and Marshal as a serializer
Faraday::HttpCache.new(app, logger: my_logger, serializer: Marshal)
# Initialize the middleware with a FileStore at the 'tmp' dir.
store = ActiveSupport::Cache.lookup_store(:file_store, ['tmp'])
Faraday::HttpCache.new(app, store: store)
# Initialize the middleware with a MemoryStore and logger
store = ActiveSupport::Cache.lookup_store
Faraday::HttpCache.new(app, store: store, logger: my_logger)
104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/faraday/http_cache.rb', line 104 def initialize(app, = {}) super(app) = .dup @logger = [:logger] @shared_cache = .delete(:shared_cache) { true } @instrumenter = .delete(:instrumenter) @instrument_name = .delete(:instrument_name) { EVENT_NAME } strategy = .delete(:strategy) { Strategies::ByUrl } @strategy = strategy.new(**) end |