rack-cache
rack-cache copied to clipboard
Rack::Cache is not multithread friendly
When using puma with Rack::Cache, the assets do not get loaded correctly, this issue is described on the puma project: https://github.com/puma/puma/issues/57
I found out that puma sets env['rack.run_once'] to true and rack-cache uses this information to determine to run the request on a non threadsafe mode, i.e. in /lib/rack/cache/context.rb:48.
def call(env)
if env['rack.run_once']
call! env
else
clone.call! env
end
end
As per rack specs (http://rack.rubyforge.org/doc/files/SPEC.html), rack.run_once is not a guaranty that the application will be served only once. The specs also describe rack.multithread if the application object may be simultaneously invoked by another thread in the same process. I'll send a pull request to add test that rack.multithread is not set to true i.e.
def call(env)
if env['rack.run_once'] && !env['rack.multithread']
call! env
else
clone.call! env
end
end