2

I'm caching the most visited page on my Rails app using HTTP caching and etags.

This is reliant on Rack::Cache, and I recently discovered I'm not explicitly setting the storage configuration for Rack::Cache anywhere in my config files or initializers (specifically, I don't have the config.action_dispatch.rack_cache bit of code anywhere, as discussed in this Heroku guide).

My implementation of HTTP caching appears to be working i.e. if a page is not modified, a logged out user gets the pages back with a 304 Not Modified response.

I fired up a Rails console from my server (in development, staging, and production), ran MyApp::Application.config.action_dispatch.rack_cache, and this is what it came back with:

=> {:metastore=>"rails:/", :entitystore=>"rails:/", :verbose=>false}

I've only ever encountered memcache, file:/, or heap:/ as options for metastore and entitystore. Never rails:/ - there's no mention of it here.

Is my Rack::Cache misconfigured? What does rails:/ mean?

DelPiero
  • 489
  • 1
  • 10
  • 21
  • 1
    You could run ```rake middleware``` in production to make sure that you have ```use Rack::Cache``` shown. You could also check your server logs for cache entries like: ```cache: [GET /some_page] miss```. The client receiving a 304 doesn't indicate anything about the proxy cache, just that the browser cache is working. – laertiades Feb 16 '15 at 04:26
  • @JesseGoodfellow Running `rake middleware` does indeed show `use Rack::Cache`. I don't see any misses in the logs. How do the proxy cache and the browser cache differ? I thought that using conditional GET with `stale?(@resource, public: true)` just meant that if the page hasn't changed, serve it from browser cache. Is that not the case? – DelPiero Feb 16 '15 at 07:25
  • 2
    ```stale?(@resource, public: true)``` will cause the server to run a database query for each request. The purpose of rack cache is to serve the entire page content from cache without the request ever reaching the stack. Each request will be handled by Rack::Cache so if you are not seeing cache entries (miss, store, fresh, stale) in your logs with each request then it is not functioning properly. – laertiades Feb 16 '15 at 16:24

0 Answers0