Class: GarageClient::Cachers::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/garage_client/cachers/base.rb

Instance Method Summary collapse

Constructor Details

#initialize(env) ⇒ Base

Returns a new instance of Base.



5
6
7
# File 'lib/garage_client/cachers/base.rb', line 5

def initialize(env)
  @env = env
end

Instance Method Details

#callObject



9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/garage_client/cachers/base.rb', line 9

def call
  response = store.read(key, options) if read_from_cache?
  if response
    # Faraday::Response#marshal_dump drops the request object
    # https://github.com/lostisland/faraday/blob/cc5d60776645d3d341ff0f425c45b3b3d48d98e0/lib/faraday/response.rb#L70
    response.env.merge!(@env)
  else
    response = yield
    store.write(key, response, options) if written_to_cache?
  end
  response
end