Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 4ec5fe071c
Fetching contributors…

Cannot retrieve contributors at this time

48 lines (41 sloc) 1.056 kb
module TemplateStreaming
module Caching
CACHER_KEY = 'template_streaming.caching.cacher'.freeze
module Controller
def cache_page(content = nil, options = nil)
if content
super
else
request.env[CACHER_KEY] = lambda { |c| super(c, options) }
end
end
end
class Middleware
def initialize(app)
@app = app
end
def call(env)
response = @app.call(env)
path = env[CACHER_KEY] and
response[2] = PageCachingBodyProxy.new(response[2], env[CACHER_KEY])
response
end
class PageCachingBodyProxy
def initialize(body, cacher)
@body = body
@cacher = cacher
end
def each
chunks = []
@body.each do |chunk|
chunks << chunk
yield chunk
end
@cacher.call(chunks.join)
end
end
end
ActionController::Base.send :include, Controller
ActionController::Dispatcher.middleware.use Middleware
end
end
Jump to Line
Something went wrong with that request. Please try again.