4

I am using Memcached in my Ruby on Rails 3 app. It works great with action and fragment caching, but when I try to use page caching, the page is stored in the filesystem instead of in Memcached. How can I tell Rails to use Memcached for page caching too?

In my development.rb file:

config.action_controller.perform_caching = true
config.cache_store = :mem_cache_store
Shlomo Zalman Heigh
  • 3,968
  • 8
  • 41
  • 71

2 Answers2

8

You cant. The equivalent of page caching in memcached is action caching, because the request must be served through Rails. Page caching is meant to bypass Rails, so the data must be stored in a file that can be served from the server, like Nginx or Apache. The reason page caching is so fast is that it does bypass Rails entirely. Here is what the Rails documentation says:

Page caching is a Rails mechanism which allows the request for a generated page to be fulfilled by the webserver (i.e. apache or nginx), without ever having to go through the Rails stack at all. Obviously, this is super-fast. Unfortunately, it can’t be applied to every situation (such as pages that need authentication) and since the webserver is literally just serving a file from the filesystem, cache expiration is an issue that needs to be dealt with.

You can find more information here.

Pan Thomakos
  • 34,082
  • 9
  • 88
  • 85
  • Can I specify where the page cache is stored? – Shlomo Zalman Heigh Apr 27 '11 at 17:22
  • 1
    Not really, since files must be served out of the public directory and to be properly served to the client they must have the same path as the file. For example: public/users/13/profile.html cannot be stored in public/user_13_profile.html because the Nginx or Apache web server will not associate this file with the latter path. – Pan Thomakos Apr 27 '11 at 17:34
0

check this :

http://globaldev.co.uk/2012/06/serving_memcached_pages_from_nginx/

Cutting it shortly, install "memcaches_page" gem (add it to GemFile then bundle), then change caches_page directive to memcaches_page, then configure Nginx to serve page memcached server before hitting the application (described in the article) .