Class: Plum::StaticCache::Middleware
- Inherits:
-
Object
- Object
- Plum::StaticCache::Middleware
- Defined in:
- lib/plum/static_cache/middleware.rb
Overview
Serves cached pages before the request reaches Rails and captures renders on the way out. Controllers opt responses in by setting the X-Plum-Static-Cache header to "store" (see PagesController); everything else passes through untouched.
Constant Summary collapse
- MARKER =
StaticCache::MARKER_HEADER.downcase
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app) ⇒ Middleware
constructor
A new instance of Middleware.
Constructor Details
#initialize(app) ⇒ Middleware
Returns a new instance of Middleware.
12 13 14 |
# File 'lib/plum/static_cache/middleware.rb', line 12 def initialize(app) @app = app end |
Instance Method Details
#call(env) ⇒ Object
16 17 18 19 20 21 22 23 |
# File 'lib/plum/static_cache/middleware.rb', line 16 def call(env) if StaticCache.enabled? && cacheable_request?(env) && (file = StaticCache.read(env["HTTP_HOST"], env["PATH_INFO"])) return serve(file, env) end status, headers, body = @app.call(env) maybe_store(env, status, headers, body) end |