Class: Locomotive::Middlewares::Cache
- Inherits:
-
Object
- Object
- Locomotive::Middlewares::Cache
- Defined in:
- lib/locomotive/middlewares/cache.rb
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, opts = {}, &block) ⇒ Cache
constructor
A new instance of Cache.
Constructor Details
#initialize(app, opts = {}, &block) ⇒ Cache
Returns a new instance of Cache.
7 8 9 10 11 12 13 14 |
# File 'lib/locomotive/middlewares/cache.rb', line 7 def initialize(app, opts = {}, &block) url_format = Locomotive::Dragonfly.app.configuration[:url_format] base_format = url_format.split('/:').first rescue '/images/dynamic' @app = app @regexp = %r{^#{base_format}/} @context = ::Rack::Cache.new(app, opts, &block) end |
Instance Method Details
#call(env) ⇒ Object
16 17 18 19 20 21 22 |
# File 'lib/locomotive/middlewares/cache.rb', line 16 def call(env) if env['PATH_INFO'] =~ @regexp @context.call(env) else @app.call(env) end end |