2011-06-28 13:38:13 +00:00
|
|
|
require 'rack/cache'
|
|
|
|
|
|
|
|
module Locomotive
|
|
|
|
module Middlewares
|
|
|
|
class Cache
|
|
|
|
|
|
|
|
def initialize(app, opts = {}, &block)
|
|
|
|
url_format = Locomotive::Dragonfly.app.configuration[:url_format]
|
|
|
|
|
2011-07-08 13:03:48 +00:00
|
|
|
base_format = url_format.split('/:').first rescue '/images/dynamic'
|
2011-06-28 13:38:13 +00:00
|
|
|
|
|
|
|
@regexp = %r{^#{base_format}/}
|
|
|
|
@app = app
|
|
|
|
@context = ::Rack::Cache.new(app, opts, &block)
|
|
|
|
end
|
|
|
|
|
|
|
|
def call(env)
|
|
|
|
if env['PATH_INFO'] =~ @regexp
|
|
|
|
@context.call(env)
|
|
|
|
else
|
|
|
|
@app.call(env)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|