Class: Heartcheck::CachingApp
- Inherits:
-
Object
- Object
- Heartcheck::CachingApp
- Defined in:
- lib/heartcheck/caching_app.rb,
lib/heartcheck/caching_app/cache.rb
Defined Under Namespace
Classes: Cache
Instance Method Summary collapse
-
#call(env) ⇒ Array
Invokes the middleware.
-
#initialize(app, ttl = 300, cache = nil) ⇒ #call
constructor
Creates an instance of the middleware.
Constructor Details
#initialize(app, ttl = 300, cache = nil) ⇒ #call
Creates an instance of the middleware
16 17 18 19 20 |
# File 'lib/heartcheck/caching_app.rb', line 16 def initialize(app, ttl = 300, cache = nil) @app = app @ttl = ttl @cache = cache end |
Instance Method Details
#call(env) ⇒ Array
Invokes the middleware
26 27 28 29 30 31 32 33 34 35 |
# File 'lib/heartcheck/caching_app.rb', line 26 def call(env) req = Rack::Request.new(env) controller = Heartcheck::App::ROUTE_TO_CONTROLLER[req.path_info] if controller && (result = cache.result(controller)) [200, { 'Content-type' => 'application/json' }, [result]] else @app.call(env) end end |