# Timed\_fragment\_cache always expires

**URL:** <https://www.ruby-forum.com/t/timed-fragment-cache-always-expires/105850>\
**Category:** Rails\
**Created:** [June 3, 2007, 8:27pm UTC](https://www.ruby-forum.com/t/timed-fragment-cache-always-expires/105850 "2007-06-03T20:27:48Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![tuktuk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/77aa72/32.png) [@tuktuk](https://www.ruby-forum.com/u/tuktuk)\
**Post date:** [June 3, 2007, 8:27pm UTC](https://www.ruby-forum.com/t/timed-fragment-cache-always-expires/105850/1 "2007-06-03T20:27:48Z")

</div>

I have downloaded the latest version of the plugin timed\_fragment\_cache.  
Which makes timed cache expiration possible in the filesystem.

My first experiment was this:

In my controller I have the following code:

when\_fragment\_expired(‘front\_popular\_races’, 10.minutes.ago) do  
@popular\_races = Race.popular  
end

And in the view:

\<% cache(‘front\_popular\_races’) do %\>  
\<% for race in @popular\_races %\>  
\<%= link\_to race.name, ‘/racehunde/’ + CGI::escape(race.name),  
:class =\> ‘race’ %\>  
  
  
\<% end %\>  
\<% end %\>

But the cached fragment file expires and gets regenerated on every  
request. What am I doing wrong?

- Carsten

---

<div class="post-metadata">

**Author:** ![tuktuk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/77aa72/32.png) [@tuktuk](https://www.ruby-forum.com/u/tuktuk)\
**Post date:** [January 23, 2008, 8:33am UTC](https://www.ruby-forum.com/t/timed-fragment-cache-always-expires/105850/2 "2008-01-23T08:33:08Z")

</div>

Are you running in development mode? Did you set:

config.action\_controller.perform\_caching = true

in environments/development.rb

Cheers,

Nick.

Carsten G. wrote:

> I have downloaded the latest version of the plugin timed\_fragment\_cache.  
> Which makes timed cache expiration possible in the filesystem.
> 
> My first experiment was this:
> 
> In my controller I have the following code:
> 
> when\_fragment\_expired(‘front\_popular\_races’, 10.minutes.ago) do  
> @popular\_races = Race.popular  
> end
> 
> And in the view:
> 
> \<% cache(‘front\_popular\_races’) do %\>  
> \<% for race in @popular\_races %\>  
> \<%= link\_to race.name, ‘/racehunde/’ + CGI::escape(race.name),  
> :class =\> ‘race’ %\>  
>   
>   
> \<% end %\>  
> \<% end %\>
> 
> But the cached fragment file expires and gets regenerated on every  
> request. What am I doing wrong?
> 
> - Carsten

---

<div class="post-metadata">

**Author:** ![tuktuk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/77aa72/32.png) [@tuktuk](https://www.ruby-forum.com/u/tuktuk)\
**Post date:** [January 23, 2008, 11:27am UTC](https://www.ruby-forum.com/t/timed-fragment-cache-always-expires/105850/3 "2008-01-23T11:27:45Z")

</div>

Nick A. wrote:

> Are you running in development mode? Did you set:
> 
> config.action\_controller.perform\_caching = true
> 
> in environments/development.rb

I was yes - this was an old question, but thanks for answering anyway  
🙂

- Carsten

---

<div class="post-metadata">

**Author:** ![tuktuk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/77aa72/32.png) [@tuktuk](https://www.ruby-forum.com/u/tuktuk)\
**Post date:** [May 31, 2008, 1:15pm UTC](https://www.ruby-forum.com/t/timed-fragment-cache-always-expires/105850/4 "2008-05-31T13:15:06Z")

</div>

Hi,

I am facing the same problem using timed\_fragment\_cache plugin.  
And do all the steps i need to do.  
it works fine for time being cache.  
But for the left all it not work it expires.

Any Idea?

Arun A.

Carsten G. wrote:

> Nick A. wrote:
> 
> > Are you running in development mode? Did you set:
> > 
> > config.action\_controller.perform\_caching = true
> > 
> > in environments/development.rb
> 
> I was yes - this was an old question, but thanks for answering anyway  
> 🙂
> 
> - Carsten

---

<div class="post-metadata">

**Author:** ![tuktuk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/77aa72/32.png) [@tuktuk](https://www.ruby-forum.com/u/tuktuk)\
**Post date:** [May 31, 2008, 1:32pm UTC](https://www.ruby-forum.com/t/timed-fragment-cache-always-expires/105850/5 "2008-05-31T13:32:42Z")

</div>

Arun A. wrote:

> Hi,
> 
> I am facing the same problem using timed\_fragment\_cache plugin.  
> And do all the steps i need to do.  
> it works fine for time being cache.  
> But for the left all it not work it expires.

I ended up choosing another approach. I am using the normal cache  
system. Then I made a cronjob, that deletes the cache files after after  
a certain amount of time.

- Carsten

---

<div class="post-metadata">

**Author:** ![tuktuk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/77aa72/32.png) [@tuktuk](https://www.ruby-forum.com/u/tuktuk)\
**Post date:** [May 31, 2008, 2:34pm UTC](https://www.ruby-forum.com/t/timed-fragment-cache-always-expires/105850/6 "2008-05-31T14:34:06Z")

</div>

On May 31, 4:32 pm, Carsten G. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> a certain amount of time.
> 
> - Carsten  
> –  
> Posted viahttp://www.ruby-forum.com/.

Carsten, Just out of curiosity, Was that because of a limitation in  
the plugin or you just wanted a cron based solution?  
Are you using capistrano to setup that cron job? Cos otherwise it  
seems like another bit to configure unless of course the plugin didnt  
meet your requirements.

Cheers,  
Aditya

---

<div class="post-metadata">

**Author:** ![tuktuk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/77aa72/32.png) [@tuktuk](https://www.ruby-forum.com/u/tuktuk)\
**Post date:** [July 23, 2008, 12:04pm UTC](https://www.ruby-forum.com/t/timed-fragment-cache-always-expires/105850/7 "2008-07-23T12:04:22Z")

</div>

Just a question on the original code.

Shouldn’t the line  
when\_fragment\_expired(‘front\_popular\_races’, 10.minutes.ago) do

be  
when\_fragment\_expired(‘front\_popular\_races’, 10.minutes.from\_now) do

?

Perhaps that’s the reason why the cache always expires.

---

<div class="post-metadata">

**Author:** ![tuktuk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/77aa72/32.png) [@tuktuk](https://www.ruby-forum.com/u/tuktuk)\
**Post date:** [May 31, 2008, 11:46pm UTC](https://www.ruby-forum.com/t/timed-fragment-cache-always-expires/105850/8 "2008-05-31T23:46:11Z")

</div>

Aditya wrote:

> Carsten, Just out of curiosity, Was that because of a limitation in  
> the plugin or you just wanted a cron based solution?  
> Are you using capistrano to setup that cron job? Cos otherwise it  
> seems like another bit to configure unless of course the plugin didnt  
> meet your requirements.

Oh it was simply, that I never succeded in getting the fragments to  
time-out and be rebuilt. After using 2 days on it, I had to quickly find  
another solution.

Our site was suddenly having a LOT of requests due to a TV commercial so  
I just had to get some cache to work quickly.

- Carsten

---

<div class="post-metadata">

**Author:** ![tuktuk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/77aa72/32.png) [@tuktuk](https://www.ruby-forum.com/u/tuktuk)\
**Post date:** [July 28, 2008, 10:35am UTC](https://www.ruby-forum.com/t/timed-fragment-cache-always-expires/105850/9 "2008-07-28T10:35:52Z")

</div>

Sean T. wrote:

> Just a question on the original code.
> 
> Shouldn’t the line  
> when\_fragment\_expired(‘front\_popular\_races’, 10.minutes.ago) do
> 
> be  
> when\_fragment\_expired(‘front\_popular\_races’, 10.minutes.from\_now) do
> 
> ?
> 
> Perhaps that’s the reason why the cache always expires.

Possibly. It’s been so long since I tried it. But I think, that I tested  
both cases, because I was in doubt myself.

Anyway it’s so long ago. 🙂

- Carsten
