Class: Yescode::RequestCache::Middleware

Inherits:
Object
  • Object
show all
Defined in:
lib/yescode/request_cache/middleware.rb

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ Middleware

Returns a new instance of Middleware.



27
28
29
# File 'lib/yescode/request_cache/middleware.rb', line 27

def initialize(app)
  @app = app
end

Instance Method Details

#call(env) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/yescode/request_cache/middleware.rb', line 31

def call(env)
  RequestCache.begin!

  status, headers, body = @app.call(env)

  body = Rack::BodyProxy.new(body) do
    RequestCache.end!
    RequestCache.clear!
  end

  returned = true

  [status, headers, body]
ensure
  unless returned
    RequestCache.end!
    RequestCache.clear!
  end
end