Forum: Ruby on Rails Rails page caching with separately cached global elements.

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
4e4730caefa10a75dc6ba2e3d50ccbad?d=identicon&s=25 Steven Hilton (mshiltonj)
on 2009-05-25 03:50
(Received via mailing list)
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
(  ) 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
<!--#include virtual="/includes/ten_newest_posts.html" -->

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

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
this work is if I can get the ssi to only conditionally include the
file if the file exists.

Something like this:

  <!--#if expr=' -e /global_elements/top10.html' -->
    <!--#include virtual="/global_elements/top10.html" -->
  <!--#else -->
     Non-dynamic text to go here.
  <!--#endif -->

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
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 Hilton <>
This topic is locked and can not be replied to.