Skip to content

Instantly share code, notes, and snippets.

@JonRowe
Created December 16, 2010 16:40
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save JonRowe/743620 to your computer and use it in GitHub Desktop.
Save JonRowe/743620 to your computer and use it in GitHub Desktop.
Async rack cache monkey patch.... use with caution
require 'async-rack'
require 'rack/cache'
module Rack::Cache
class Context
include AsyncRack::AsyncCallback::Mixin
def async_callback(result)
response = Response.new(*result)
@request ||= Request.new(env.dup.freeze)
store response if response.cacheable?
super result
end
def call(env)
setup_async env
if env['rack.run_once']
call! env
else
clone.call! env
end
end
end
end
@raphaelcosta
Copy link

this still works?

@JonRowe
Copy link
Author

JonRowe commented Sep 7, 2011

As far as I know

@raphaelcosta
Copy link

Hi, i am trying to use with Cramp , do you know why i am not receiving any response?

@JonRowe
Copy link
Author

JonRowe commented Oct 12, 2011

Pass, haven't used Cramp, this requires an async compatible server obviously like thin/rainbows/goliath, and it relies on the async_callback being called from on high. IIRC thin triggers this with a status of -1 and other things use throw :async. I was using async_sinatra with this so that'd be the place to look for clues.

Sorry for the delay in the response especially since I'm not much help :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment