Rails page caching with separately cached global elements


#1

I’m trying to build an optimized caching setup for my app.

Large parts of the app will use full page caching (using something
like Ben Scofield’s Progressive Enhancement approach

The issue is: I’d like to include some global elements on all pages,
where the global element changes much more rapidly that most other
pages on the site, and I don’t want to expire nearly all the pages on
the site because a minor global element needs to be updated.

An example of this is “10 most recent blog posts.” shown on every
page. The RailsEnvy tutorial on caching
(http://www.railsenvy.com/2007/2/28/rails-caching-tutorial ) uses
this example as a case where you would need to clear the whole
cache, so maybe I’m being a little too creative here.

I was hoping to do this with SSI as apache serves the cached pages, as
in:

This doesn’t work because:
1: On the rails side, if page caching is turned off, the include is
ignored and the element is empty when the page is rendered
dynamically.

2: If the page is cached, but the element included via ssi doesn’t
exist on the file system, it results in a routing error.

Google says some people have tried this, but I haven’t seen a howto or
successful report of this approach. After fumbling around and
searching for a couple hours, I get the sense that this is trickier
than it sounds:

  • Knowing when the SSI include statement should be processed by rails
    or by apache2
  • Getting apache to ssi include a file that doesn’t exist and needs to
    be generated on the fly
  • Getting rails to include the ssi content served to the client, by
    not including the ssi for the content cached to the file system

So, I’m looking for alternative approaches or more input on this
approach. Is something like this even possible now? One thing that may
make
this work is if I can get the ssi to only conditionally include the
file if the file exists.

Something like this:

<!--#include virtual="/global_elements/top10.html" -->
 Non-dynamic text to go here.

But SSI doesn’t seem to support file tests or some similar workaround
that I’ve found

I could (and may) use a javascript layering approach on the client
side,
but then the content in the global elements would not be visible to
spiders used to build search indexes, which is not really desirable.

Thanks for any feedback.


Steven H. removed_email_address@domain.invalid