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 is drop request object and url
    # https://github.com/lostisland/faraday/blob/edacd5eb57ea13accab3097649690ae5f48f421a/lib/faraday/response.rb#L74
    response.env.merge!(@env) {|_, self_val, other_val| self_val || other_val }
  else
    response = yield
    store.write(key, response, options) if written_to_cache?
  end
  response
end