Class: Routemaster::Middleware::ResponseCaching
- Inherits:
-
Object
- Object
- Routemaster::Middleware::ResponseCaching
- Defined in:
- lib/routemaster/middleware/response_caching.rb
Constant Summary collapse
- BODY_FIELD_TEMPLATE =
'v:{version},l:{locale},body'.freeze
- HEADERS_FIELD_TEMPLATE =
'v:{version},l:{locale},headers'.freeze
- VERSION_REGEX =
/application\/json;v=(?<version>\S*)/
- RESPONSE_CACHING_OPT_HEADER =
'X-routemaster_drain.opt_cache'.freeze
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, options = {}) ⇒ ResponseCaching
constructor
A new instance of ResponseCaching.
Constructor Details
#initialize(app, options = {}) ⇒ ResponseCaching
Returns a new instance of ResponseCaching.
13 14 15 16 17 18 |
# File 'lib/routemaster/middleware/response_caching.rb', line 13 def initialize(app, = {}) @app = app @cache = .fetch(:cache) { Config.cache_redis } @expiry = Config.cache_expiry @listener = [:listener] end |
Instance Method Details
#call(env) ⇒ Object
20 21 22 23 24 |
# File 'lib/routemaster/middleware/response_caching.rb', line 20 def call(env) @cache.del(cache_key(env)) if %i(patch delete).include?(env.method) return @app.call(env) if env.method != :get fetch_from_cache(env) || fetch_from_service(env, event_index(env)) end |