# Time-based cache fragment expiration

**URL:** <https://www.ruby-forum.com/t/time-based-cache-fragment-expiration/61864>\
**Category:** Rails\
**Created:** [May 29, 2006, 4:07am UTC](https://www.ruby-forum.com/t/time-based-cache-fragment-expiration/61864 "2006-05-29T04:07:49Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![phillyloco](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/258eb7/32.png) [@phillyloco](https://www.ruby-forum.com/u/phillyloco)\
**Post date:** [May 29, 2006, 4:07am UTC](https://www.ruby-forum.com/t/time-based-cache-fragment-expiration/61864/1 "2006-05-29T04:07:49Z")

</div>

Hello,

I’m trying to figure out how I could implement fragment caching that  
expires every x amount of time. I thought of writing a runner script  
that would expire the cache and set it as a cron job, but that  
doesn’t really work because runner scripts act on models and not  
controllers.

Does anybody have any ideas?

Regards,  
-carl

---

<div class="post-metadata">

**Author:** ![phillyloco](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/258eb7/32.png) [@phillyloco](https://www.ruby-forum.com/u/phillyloco)\
**Post date:** [May 31, 2006, 2:16am UTC](https://www.ruby-forum.com/t/time-based-cache-fragment-expiration/61864/2 "2006-05-31T02:16:22Z")

</div>

I was hoping someone would jump in here with the solution. I had the  
same  
problem and couldn’t figure it out. I ended up just using a cron job to  
delete them.

Steve  
[http://www.trivionomy.com](http://www.trivionomy.com)  
[http://www.smarkets.net](http://www.smarkets.net)

---

<div class="post-metadata">

**Author:** ![phillyloco](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/258eb7/32.png) [@phillyloco](https://www.ruby-forum.com/u/phillyloco)\
**Post date:** [May 31, 2006, 3:06am UTC](https://www.ruby-forum.com/t/time-based-cache-fragment-expiration/61864/3 "2006-05-31T03:06:05Z")

</div>

I believe the Typo project has done what you need. Take a look at  
[http://www.typosphere.org/trac/browser/trunk/vendor/plugins/expiring\_action\_cache/lib/metafragment.rb](http://www.typosphere.org/trac/browser/trunk/vendor/plugins/expiring_action_cache/lib/metafragment.rb)

I’ve been meaning to implement this, but its low on my priority list.

cheers,

scott

* * *

What’s an Intel chip doing in a Mac? A whole lor more that it’s ever  
done in a PC.

My Digital Life - [http://scottwalter.com/blog](http://scottwalter.com/blog)  
Pro:Blog - [http://scottwalter.com/problog](http://scottwalter.com/problog)  
Snippets - [http://snippets.scottwalter.com](http://snippets.scottwalter.com)

----- Original Message ----  
From: Steve O. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
To: removed\_email\_address@domain.invalid  
Sent: Tuesday, May 30, 2006 7:15:44 PM  
Subject: Re: [Rails] Time-based cache fragment expiration

I was hoping someone would jump in here with the solution. I had the  
same problem and couldn’t figure it out. I ended up just using a cron  
job to delete them.

Steve  
[http://www.trivionomy.com](http://www.trivionomy.com)  
[http://www.smarkets.net](http://www.smarkets.net)

On 5/28/06, Carl L. \<removed\_email\_address@domain.invalid \> wrote:Hello,

I’m trying to figure out how I could implement fragment caching that  
expires every x amount of time. I thought of writing a runner script  
that would expire the cache and set it as a cron job, but that  
doesn’t really work because runner scripts act on models and not  
controllers.

Does anybody have any ideas?

Regards,  
-carl

* * *

Rails mailing list  
removed\_email\_address@domain.invalid  
[http://lists.rubyonrails.org/mailman/listinfo/rails](http://lists.rubyonrails.org/mailman/listinfo/rails)

---

<div class="post-metadata">

**Author:** ![phillyloco](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/258eb7/32.png) [@phillyloco](https://www.ruby-forum.com/u/phillyloco)\
**Post date:** [May 31, 2006, 8:37pm UTC](https://www.ruby-forum.com/t/time-based-cache-fragment-expiration/61864/4 "2006-05-31T20:37:46Z")

</div>

> Hello,
> 
> I’m trying to figure out how I could implement fragment caching that expires  
> every x amount of time. I thought of writing a runner script that would  
> expire the cache and set it as a cron job, but that doesn’t really work  
> because runner scripts act on models and not controllers.
> 
> Does anybody have any ideas?

I haven’t done extensive testing, but we use memcache to store  
sessions/fragments and with some minor tweaks you can pass along an  
expiration time (ie. expire automatically in 10 minutes)…

The automatic expiration is a part of memcache… if you’re interested  
let  
me know and I’ll write it up.

-philip

---

<div class="post-metadata">

**Author:** ![phillyloco](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/258eb7/32.png) [@phillyloco](https://www.ruby-forum.com/u/phillyloco)\
**Post date:** [June 1, 2006, 2:41pm UTC](https://www.ruby-forum.com/t/time-based-cache-fragment-expiration/61864/5 "2006-06-01T14:41:18Z")

</div>

I’ve done it with using MemCached as a cache backend and described it  
here:

[http://blog.innerewut.de/articles/2006/02/09/time-based-fragment-caching-with-memcache](http://blog.innerewut.de/articles/2006/02/09/time-based-fragment-caching-with-memcache)

Jonathan
