Class: Murlsh::MustRevalidate
- Inherits:
-
Object
- Object
- Murlsh::MustRevalidate
- Defined in:
- lib/murlsh/must_revalidate.rb
Overview
Rack middleware to force caches to always revalidate for urls that match patterns.
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, options = {}) ⇒ MustRevalidate
constructor
A new instance of MustRevalidate.
Constructor Details
#initialize(app, options = {}) ⇒ MustRevalidate
Returns a new instance of MustRevalidate.
10 11 12 13 |
# File 'lib/murlsh/must_revalidate.rb', line 10 def initialize(app, ={}) @app = app @patterns = Array([:patterns]) end |
Instance Method Details
#call(env) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/murlsh/must_revalidate.rb', line 15 def call(env) status, headers, body = @app.call(env) req = Rack::Request.new(env) headers = Rack::Utils::HeaderHash.new(headers) @patterns.each do |pattern| if pattern.match(req.path) headers['Cache-Control'] = 'must-revalidate, max-age=0' break end end [status, headers, body] end |