# Fragment cache expiry problem

**URL:** <https://www.ruby-forum.com/t/fragment-cache-expiry-problem/116012>\
**Category:** Rails\
**Created:** [October 1, 2007, 5:03pm UTC](https://www.ruby-forum.com/t/fragment-cache-expiry-problem/116012 "2007-10-01T17:03:40Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![rob](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/838e76/32.png) [@rob](https://www.ruby-forum.com/u/rob)\
**Post date:** [October 1, 2007, 5:03pm UTC](https://www.ruby-forum.com/t/fragment-cache-expiry-problem/116012/1 "2007-10-01T17:03:40Z")

</div>

Hi,

I’ve been wrestling with various different caching options for the last  
couple of days and am stuck with one specific problem, to which I can’t  
find any clues anywhere.

Here is the essence of it:

What would cause fragment caching to constantly expire by default?

And here are some details:

I have an index page which has some content that is populated by a call  
to an external service. Since this content changes once every couple of  
minutes, I need to cache in a way which will expire automatically after  
2 minutes. The rest of the page stays the same between one deployment  
and the next, so my plan was to cache the page in 3 fragments: 2 of  
which contain content which doesnâ€™t change, and 1 of which contains the  
dynamic content. Since Rails unfortunately lacks any facilities for  
timed cache expiry by default, I was going to use the  
timed\_fragment\_cache plugin  
([http://livsey.org/2006/8/25/timed\_fragment\_cache-plugin-fragment-caching-with-time-based-expiry/](http://livsey.org/2006/8/25/timed_fragment_cache-plugin-fragment-caching-with-time-based-expiry/))  
to expire the cache of this dynamic fragment.

The fragments are produced just as they should be when a page is first  
called up, and they are read when the page is called again. The only  
problem is that they are expired immediately, which means that the cache  
gets expired and rebuilt with every single request, which obviously  
makes the cache completely pointless!!

My initial thought was that this must be a bug introduced by the  
timed\_fragment\_cache plugin. However, even after uninstalling this  
plugin I still have the same problem. The question is, why are these  
fragments expiring at all? A fragment that is cached should stay the  
same until it is specifically made to expire. What could there be that  
might cause it to expire without any prompting?

It even doesnâ€™t work when I wrap the whole index action in an:

unless read\_fragmentâ€¦

Rather, what happens here is that the code in the index action only gets  
executed the first time the page is requested, but the cache itself gets  
expired and rebuilt on every further request. This means that the page  
content appears once and then vanishes! So, my application is  
recognising that there is a cached version of the page, and acting  
accordingly, but still expiring and rebuilding the fragment.

Any ideas?

Thanks,

Rob.
