rtomayko / rack-cache

Real HTTP Caching for Ruby Web Apps
http://rtomayko.github.io/rack-cache/
Other
822 stars 124 forks source link

No files are stored #142

Closed brunofacca closed 7 years ago

brunofacca commented 7 years ago

First let me thank you for this great gem.

Before using rack-cache on production servers, I'm attempting to familiarize myself with it in the development environment.

I have included the following in config/application.rb

config.middleware.use Rack::Cache,
   verbose:     true,
   metastore:   'file:/var/cache/rack/meta',
   entitystore: 'file:/var/cache/rack/body'
config.action_dispatch.rack_cache = true

After restarting the Rails development server and performing multiple requests, both /var/cache/rack subdirectories are still empty and all requests display miss, store in the log and in the X-Rack-Cache header.

I have also attempted to use the heap store and, again, it appears that nothing is being cached (all requests result in miss, store).

Could you please advise on how to make Rack::Cache actually cache (store) the files in development mode?

Thanks in advance.

grosser commented 7 years ago

idk what exactly the issue is ... I'd recommend a bundle open rack-cache and then puts ing inside the middleware or file cache to see what exactly is going on

brunofacca commented 7 years ago

Thanks for your guidance.

I have done as you suggested and found that I could not see any files being stored in /var/cache/rack because they were being stored in Rails.root/tmp/cache.

By setting config.action_dispatch.rack_cache to true, Rails automatically adds Rack::Cache to the middleware stack with the following options: {:metastore=>"rails:/", :entitystore=>"rails:/", :verbose=>false}. See the Rails source code here and here.

So the following code in config/application.rb was adding Rack::Cache to the middleware stack twice and the options I have provided were overridden by Rails' default options.

config.middleware.use Rack::Cache,
                      verbose:     true,
                      metastore:   'file:/var/cache/rack/meta',
                      entitystore: 'file:/var/cache/rack/body'
# Unintentionally add Rack::Cache to the middleware for the second time
config.action_dispatch.rack_cache = true
grosser commented 7 years ago

hopefully prevented with https://github.com/rtomayko/rack-cache/pull/143