# Partial Caching - Extension Idea

**URL:** <https://www.ruby-forum.com/t/partial-caching-extension-idea/125669>\
**Category:** Radiant CMS\
**Created:** [January 11, 2008, 2:33am UTC](https://www.ruby-forum.com/t/partial-caching-extension-idea/125669 "2008-01-11T02:33:48Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mario\_TSL](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/df705f/32.png) [@Mario\_TSL](https://www.ruby-forum.com/u/Mario_TSL)\
**Post date:** [January 11, 2008, 2:33am UTC](https://www.ruby-forum.com/t/partial-caching-extension-idea/125669/1 "2008-01-11T02:33:48Z")

</div>

In the Radiant-based application I’m developing, it is necessary to  
dynamically generate pages rather than allow for caching. The  
frustrating part of this is that for most pages the majority of the page  
is static content. Only bits of the page are dynamic. Nevertheless,  
this requirement necessitates that caching be turned off.

I hate having to take one benefit and throw it out the window because of  
a separate need which takes precedence. This got me thinking about a  
hybrid solution, a way of allowing the majority of the page to be cached  
while also allowing the dynamic bits to be generated on every page  
rendering–the best of both worlds, no sacrifices.

The way I devised for handing this in an extension which extends Radius  
to accept a “cache” attribute (which defaults to ‘yes’ when not  
supplied) on all tags:

\<r:snippet name=‘current\_user’ cache=‘no’ /\>

Such tags when encountered, would be written as is to the cache file  
without expanding them. Later, in response to a page request the page  
is rendered from the cache and such tags are dynamically expanded at  
that moment.

---- IMPLEMENTATION NOTE ----

Nested tags…

\<r:special\_tag cache=‘yes’\>  
\<r:inner\_tag /\>  
\</r:special\_tag\>

\<r:some\_tag cache=‘no’\>  
\<r:inner\_tag cache=‘yes’ /\>  
\</r:some\_tag\>

…become on the cached page…

SPECIAL  
OUTPUT  
FROM  
TAGS

\<r:some\_tag cache=‘no’\>  
\<r:inner\_tag cache=‘yes’ /\>  
\</r:some\_tag\>

…whereby inner tags regardless of their cached attribute are left  
alone.

---- TAKING IT FURTHER ----

Though I don’t see this as necessity, a slightly more advanced version  
would accept a time period in the “cache” attribute.

\<r:uber\_impressive\_tag cache=“5 minutes” /\>

Then when generated to the cache (at 5pm) we save the tag as:

\<r:uber\_impressive\_tag cached\_until=“2008-01-10 5:05 PM” /\>

Other than timezone issues, the final details of implementation are  
obvious.

---- TAKING IT STILL FURTHER ----

Snippets would include a “never cache” checkbox so that you wouldn’t  
need to remember which ones required the cache=‘no’ setting every time  
you made use of them.

I’m sorry that numerous responsibilities prevent me from focusing on  
this anytime soon. Furthermore, it might take me far longer to learn to  
do what another experienced Radiant developer could accomplish in  
several hours.

Does this seem useful? Is it a good approach?  
Thanks for any feedback.  
Mario

PS: Orginally I had added this to the documentation wiki “Extension  
Ideas” page, but somehow it got lost. I am sure it was there at one  
point because I viewed it after saving the edit. I checked the revision  
history, no sign of it. Frustrating.

---

<div class="post-metadata">

**Author:** ![Mario\_TSL](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/df705f/32.png) [@Mario\_TSL](https://www.ruby-forum.com/u/Mario_TSL)\
**Post date:** [January 11, 2008, 3:30pm UTC](https://www.ruby-forum.com/t/partial-caching-extension-idea/125669/2 "2008-01-11T15:30:03Z")

</div>

Mario,

You might look into RevolutionOnRails’ Edge-side includes plugin, which  
essentially uses directives like server-side includes to move fragment  
caching into the server layer rather than the application layer.  
However, if your pages are taking a long time to render, it’s probably  
worth profiling them with ruby-prof before you consider adding  
infrastructure. In optimizing some of my past Rails apps, I found  
inefficient algorithms more often than I found the need to add caching.

Sean

---

<div class="post-metadata">

**Author:** ![Mario\_TSL](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/df705f/32.png) [@Mario\_TSL](https://www.ruby-forum.com/u/Mario_TSL)\
**Post date:** [January 12, 2008, 5:20am UTC](https://www.ruby-forum.com/t/partial-caching-extension-idea/125669/3 "2008-01-12T05:20:13Z")

</div>

Good points, Sean. As I have time I will investigate your suggestions.  
Thanks for the feedback!
