Different page caching folder for different domains


#1

Hi,

I created a multi-domain application, and I wanted to add page caching,
how can I tell Rails that it should save each cached page under a
subfolder such as public/www.mysite1.com/ and public/www.mysite2.com


#2

On Tue, Mar 24, 2009 at 2:07 PM, Fernando P. <
removed_email_address@domain.invalid> wrote:

Hi,

I created a multi-domain application, and I wanted to add page caching,
how can I tell Rails that it should save each cached page under a
subfolder such as public/www.mysite1.com/ and public/www.mysite2.com

If you’re using page caching, then the cached page should located
relative
to
the root of your website. Thus, if you were to access the index page on
both
www.mysite1.com and www.mysite2.com, the you should be able to find an
index.html in the following locations:

URL: www.mysite1.com/index.html On Disk:
/rails-app1/public/index.html
URL: www.mysite2.com/index.html On Disk:
/rails-app2/public/index.html

Now, if you really want to change the location of the cached pages to
use
another
directory other than the above, you can do the following:

Moving your Page Cache

First you’d want to add the following to your /config/environment.rb:

config.action_controller.page_cache_directory = RAILS_ROOT +
“/public/cache/”

This tells Rails to publish all your cached files in the /public/cache
directory. You would then want to change your Rewrite rules in your *
httpd.conf* to be:

12345

Rewrite index to check for static RewriteRule ^/$

cache/index.html [QSA] # Rewrite to check for Rails cached page
RewriteRule ^([^.]+)$ cache/$1.html [QSA]

If you would like to learn more about the wonderful world of caching, I
would recommend reading the following:

http://railslab.newrelic.com/

Good luck,

-Conrad