Class: Locomotive::Steam::Middlewares::Cache

Inherits:
Object
  • Object
show all
Defined in:
lib/locomotive/steam/middlewares/cache.rb

Constant Summary collapse

CACHEABLE_REQUEST_METHODS =
%w(GET HEAD).freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ Cache

Returns a new instance of Cache.



11
12
13
# File 'lib/locomotive/steam/middlewares/cache.rb', line 11

def initialize(app)
  @app = app
end

Instance Attribute Details

#appObject (readonly)

Returns the value of attribute app.



7
8
9
# File 'lib/locomotive/steam/middlewares/cache.rb', line 7

def app
  @app
end

Instance Method Details

#call(env) ⇒ Object



15
16
17
18
19
20
21
# File 'lib/locomotive/steam/middlewares/cache.rb', line 15

def call(env)
  if cacheable?(env)
    fetch_cached_response(env)
  else
    app.call(env)
  end
end