Class: CacheMiddalware

Inherits:
Faraday::Middleware
  • Object
show all
Defined in:
lib/binking/cache_middalware.rb

Constant Summary collapse

DEFAULT_CONDITIONS =
->(env) { env.method == :get || env.method == :head }
DEFAULT_CACHE_KEY =
->(env) { env.url }

Instance Method Summary collapse

Constructor Details

#initialize(app, store, *args) ⇒ CacheMiddalware

Returns a new instance of CacheMiddalware.



5
6
7
8
9
10
11
12
13
14
# File 'lib/binking/cache_middalware.rb', line 5

def initialize(app, store, *args)
  super(app)
  options = args.first || {}

  @store         = store
  @conditions    = options.fetch(:conditions, DEFAULT_CONDITIONS)
  @expires_in    = options.fetch(:expires_in, 30)
  @logger        = options.fetch(:logger, nil)
  @cache_key     = options.fetch(:cache_key, DEFAULT_CACHE_KEY)
end

Instance Method Details

#call(env) ⇒ Object



16
17
18
# File 'lib/binking/cache_middalware.rb', line 16

def call(env)
  dup.call!(env)
end