# Cannot expire cache from background process?

**URL:** <https://www.ruby-forum.com/t/cannot-expire-cache-from-background-process/149692>\
**Category:** Rails\
**Created:** [September 28, 2008, 1:10pm UTC](https://www.ruby-forum.com/t/cannot-expire-cache-from-background-process/149692 "2008-09-28T13:10:12Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![justus](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/b2d939/32.png) [@justus](https://www.ruby-forum.com/u/justus)\
**Post date:** [September 28, 2008, 1:10pm UTC](https://www.ruby-forum.com/t/cannot-expire-cache-from-background-process/149692/1 "2008-09-28T13:10:12Z")

</div>

Hello,

I am trying to expire fragments (or at least trigger their expiration)  
from a daemon that’s running in the background.

The daemon is updating all kinds of important lists every few minutes  
from the background.

So I have to find some way to DO or TRIGGER the fragment caching from  
this daemon.

Unfortunately just using the normal commands like:

expire\_fragment :controller =\> ‘groups’, :action =\> ‘index’

from within the daemon triggers no reaction. Is there anyting I could  
change in the parameters I could add that would fix it?

Using a sweeper is a problem because the daemon updates a lot of models  
but the cache should only be expired when a full round of updating is  
completed – not with every single update of every single db entry. Fro  
this purpose I created a Model to count the rounds - and then trigger  
cache expiration after each ‘create’ of this counter. But this counter  
model is not updated from any controller in the application - which - as  
far as I understand it - is required to make the sweeper work.

Any help would be greatly appreciated!  
Thanks!  
Justus

---

<div class="post-metadata">

**Author:** ![justus](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/b2d939/32.png) [@justus](https://www.ruby-forum.com/u/justus)\
**Post date:** [September 29, 2008, 12:02pm UTC](https://www.ruby-forum.com/t/cannot-expire-cache-from-background-process/149692/2 "2008-09-29T12:02:40Z")

</div>

Ok I’ll try to keep the question a bit shorter in the hope of increasing  
the chances that somebody understands what my problem is:

How can I expire the fragement cache from a daemon located in my lib  
folder?

This does not work:

expire\_fragment :controller =\> ‘groups’, :action =\> ‘index’

Apparently the daemon cannot speak directly to the rails app? Or can I  
fix it by modifying the parameters of the expire\_fragment command?

Thanks,  
Justus

---

<div class="post-metadata">

**Author:** ![justus](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/b2d939/32.png) [@justus](https://www.ruby-forum.com/u/justus)\
**Post date:** [September 29, 2008, 2:30pm UTC](https://www.ruby-forum.com/t/cannot-expire-cache-from-background-process/149692/3 "2008-09-29T14:30:49Z")

</div>

Justus O. wrote:

> Ok I’ll try to keep the question a bit shorter in the hope of increasing  
> the chances that somebody understands what my problem is:
> 
> How can I expire the fragement cache from a daemon located in my lib  
> folder?

Have you tried Rails.cache.delete(‘views/groups/index.html’)

(I think that’s the default path creation, given that you set the  
config.cache\_store properly in environment.rb)

---

<div class="post-metadata">

**Author:** ![justus](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/b2d939/32.png) [@justus](https://www.ruby-forum.com/u/justus)\
**Post date:** [December 12, 2008, 7:41am UTC](https://www.ruby-forum.com/t/cannot-expire-cache-from-background-process/149692/4 "2008-12-12T07:41:48Z")

</div>

Hey Justus,

Any luck with finding a solution? I’m in the same situation and need  
to be able to run expire\_fragment manually from the model or daemon.  
Would love to know if you found a work around.

On Sep 30, 12:37 am, Justus O. \<rails-mailing-l…@andreas-

---

<div class="post-metadata">

**Author:** ![justus](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/b2d939/32.png) [@justus](https://www.ruby-forum.com/u/justus)\
**Post date:** [December 12, 2008, 9:49am UTC](https://www.ruby-forum.com/t/cannot-expire-cache-from-background-process/149692/5 "2008-12-12T09:49:14Z")

</div>

Marston A. wrote:

> Hey Justus,
> 
> Any luck with finding a solution? I’m in the same situation and need  
> to be able to run expire\_fragment manually from the model or daemon.  
> Would love to know if you found a work around.
> 
> On Sep 30, 12:37ï¿½am, Justus O. \<rails-mailing-l…@andreas-

No, I didn’t find a way to expire the cache from the daemon. My  
workaround is to just let the fragments expire automatically by setting  
a shorter expiration time in the memcached.yml. (for example, ttl: 300)  
Justus

---

<div class="post-metadata">

**Author:** ![justus](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/b2d939/32.png) [@justus](https://www.ruby-forum.com/u/justus)\
**Post date:** [September 30, 2008, 10:37am UTC](https://www.ruby-forum.com/t/cannot-expire-cache-from-background-process/149692/6 "2008-09-30T10:37:29Z")

</div>

Ar Chron wrote:

> Justus O. wrote:
> 
> > Ok I’ll try to keep the question a bit shorter in the hope of increasing  
> > the chances that somebody understands what my problem is:
> > 
> > How can I expire the fragement cache from a daemon located in my lib  
> > folder?
> 
> Have you tried Rails.cache.delete(‘views/groups/index.html’)
> 
> (I think that’s the default path creation, given that you set the  
> config.cache\_store properly in environment.rb)

Thanks, Ar. But unfortunately this doesn’t work either.

How would I set the config.cache\_store properly? I have just used the  
default setup. (except for setting  
config.action\_controller.perform\_caching = true)

BTW. I would be fine with deleting the entire cache - no need for any  
specifications. Shouldn’t that make it very easy??

Thanks again,  
Justus
