Dynamic page caching directory based on subdomain name

I am looking for the best way to set the cache directory based on the
subdomain.

Example :
if the subdomain host is fr.mydomain.com, i want to cache the file in
ROOT/cache/fr and if it is en.mydomain.com, i want to cache the file in
ROOT/cache/en

The problem is that the cache directory is set in the config part of
rails and i dont know how to change it in realtime.

Any good advice ?

ps:
In my nginx config, of course, i would rewrite the uri based on this
subdomain. This part is already working.

Here’s something I just posted on my blog yesterday about storing a
cached file. This applies to both action and page caching.

I assume you could specify the path at runtime based off the subdomain
you’re using.

Also, take a look at the documentation in
action_controller/caching/pages.rb file:
http://github.com/rails/rails/tree/master/actionpack/lib/action_controller/caching/pages.rb.

– Josh

Jm Goem wrote:

I am looking for the best way to set the cache directory based on the
subdomain.

Example :
if the subdomain host is fr.mydomain.com, i want to cache the file in
ROOT/cache/fr and if it is en.mydomain.com, i want to cache the file in
ROOT/cache/en

The problem is that the cache directory is set in the config part of
rails and i dont know how to change it in realtime.

Any good advice ?

ps:
In my nginx config, of course, i would rewrite the uri based on this
subdomain. This part is already working.

Thank you for this info. I guess you meant this post
http://thereverend.tumblr.com/post/36941827/rails-2-1-action-caching

Great blog by the way :slight_smile:

I read the comments in the code of ror and understand better how it
works. Actually it is quite simple and i will probably rewrite the right
method.

OK so i rewrite cache_page with something like :

class ApplicationController < ActionController::Base

class << self
def cache_page content, path
super content, @lang + path
end
end
end

where @lang is set in a before_filter of my controller. But it does not
work ! @lang is nil so i get an error like “The error occurred while
evaluating nil.+):”

I am missing something? How do i access @lang ?

Thank you in advance