Page caching with custom route

I know the subject has been discussed a lot already, and there’s
plenty of articles about it on the web. But I still haven’t figured
out a solution to my problem, so here goes a cry for help.

I have the following custom route in my application:
map.connect ‘/:username’, :controller => ‘public’, :action =>
‘show_profile’

Basically, I want my users to be able to access their personal page
through the “shortcut” mywebsite.com is available for purchase - Sedo.com, so once that URL is
entered or clicked, I redirect them to the appropriate action, which
is show_profile. There I have a simple code, kinda like this

@user = User.find_by_username(params[:username])

to retrieve their data from the DB.

This solution works great, but since their personal pages will be
rarely updated, I want to use page caching to store it in a HTML file
and avoid all Rails processing/DB queries, expiring the cache just
when I actually need to.

And now enters my problem. Rails is saving the cached pages as
show_profile.html. That clearly doesn’t work, since each user must
have a different cached HTML with their specific data. I want the
cached HTML files to be named after the username (username.html) not
after the action (show_profile.html).

I’ve managed to make this work by adding the controller and action to
the route, like this

map.connect ‘/public/show_profile/:username’, :controller =>
‘public’, :action => ‘show_profile’

and then my cached files would be stored in a ‘public/show_profile/
username.html’ path.
But I really need the URLs to be simple as mywebsite.com is available for purchase - Sedo.com,
so that doesn’t work. And as only fragment caching accepts a
‘action_suffix’ parameter, I really can’t figure how to work this out
with page caching.

Any ideas?

Thanks,

Konrad

I know the subject has been discussed a lot already, and there’s
plenty of articles about it on the web. But I still haven’t figured
out a solution to my problem, so here goes a cry for help.

I have the following custom route in my application:
map.connect ‘/:username’, :controller => ‘public’, :action =>
‘show_profile’

I don’t know, but I suspect Rails wants some sort of “anchor” before it
will cache. Maybe not.

But for example, what happens if I create a user one your site named
“images” or “javascripts” ? That’s going to conflict with existing
directories in RAILS_ROOT/public

Just something to think about. You may want to move it “down a
level”.

-philip

That wouldn’t really be a problem, since I’ve configured my page
caching path to be under RAILS_ROOT/public/cache and I also get to
choose their usernames.

Right now the cached page, show_profile.html, is been kept in the
public/cache/public path (this last public directory is due to my
controller, named ‘public’). The path is fine, I just need to be able
to name the cached files after my usernames, not my action.