Forum: Ruby on Rails expire_fragment from observer (not sweeper!)

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
John L. (Guest)
on 2007-04-15 04:02
(Received via mailing list)
Hi all,

I'm trying to expire a cached fragment when a model is updated.  The
usual way to do this is with a sweeper, but sweepers only work when an
action is being called at the same time - I need to expire a cached
fragment during some back-end batch process.

A normal observer should work, but you don't have access to the
expire_fragment method from there.

Adding "include ActionController::Caching::Fragments" in my observer
gives me access this method, but re-runs the fragment_cache_store
initialise method and resets my config to the default MemoryStore.

I have a few options, (such as: copy and paste the expire_fragment
method into my observer, reconfig the fragment_cache_store after
inclusion, make my batch process make a http call to a controller
action to kill the cache), but these all seem pretty ugly.

Does anyone know if there is an easier way to get access to this
method from within my observer?

Thanks,

John.
--
http://johnleach.co.uk
This topic is locked and can not be replied to.