Marston A.
2008-Dec-15 18:08 UTC
Expire_fragment in observer/model? Works fine in Sweepers.
I''ve pretty much tried everything, but it seems impossible to use expire_fragment from models? I know you''re not supposed to and it''s non-MVC, but surely there much be some way to do it. I created a module in /lib/cache_helper.rb with all my expire helpers, within each are just a bunch of expire_fragment calls. I have all my cache sweepers setup under /app/sweepers and have an "include CacheHelper" in my application controller so expiring cache within the app when called via controllers works fine. Then things is I have some external daemons and especially some recurring cron tasks which call a rake task that calls a certain method. This method does some processing and inputs entries into the model, after which I need to expire cache. What''s the best way to do this as I can''t specify "cache_sweeper" within the model. Straight up observers seem to be the best solution but then it complains about expire_fragment being undefined etc etc, I''ve even tried including the ActionController caching classes into the observer but that didn''t work. I''d love some ideas of how to create a solution for this. Thanks. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Steven Cummings
2010-Sep-08 13:20 UTC
Re: Expire_fragment in observer/model? Works fine in Sweepers.
Marston A. wrote:> I''ve pretty much tried everything, but it seems impossible to use > expire_fragment from models? I know you''re not supposed to and it''s > non-MVC, but surely there much be some way to do it. > > I created a module in /lib/cache_helper.rb with all my expire helpers, > within each are just a bunch of expire_fragment calls. I have all my > cache sweepers setup under /app/sweepers and have an "include > CacheHelper" in my application controller so expiring cache within the > app when called via controllers works fine. > > Then things is I have some external daemons and especially some > recurring cron tasks which call a rake task that calls a certain > method. This method does some processing and inputs entries into the > model, after which I need to expire cache. What''s the best way to do > this as I can''t specify "cache_sweeper" within the model. > > Straight up observers seem to be the best solution but then it > complains about expire_fragment being undefined etc etc, I''ve even > tried including the ActionController caching classes into the observer > but that didn''t work. I''d love some ideas of how to create a solution > for this. Thanks.Had this problem too and wrote up the solution the other night on my blog. http://stevencummings.name/2010/09/07/expire_fragment-with-rake-and-as-a-model-only-observer -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Ar Chron
2010-Sep-08 14:30 UTC
Re: Expire_fragment in observer/model? Works fine in Sweepers.
Steven Cummings wrote:> > Had this problem too and wrote up the solution the other night on my > blog. > > http://stevencummings.name/2010/09/07/expire_fragment-with-rake-and-as-a-model-only-observerInteresting solution... Related to model-based cache expiration, in one large-ish Rails project, the sidebar for a ''show'' of an entity contains a view of all the related entities in the application. We were getting hammered on both db access and rendering time, so I implemented fragment caching in a multi-tiered approach, and left it to the models to expire caches of their data -- a fine line to walk, but that worked the best for us. We used a Rails.cache.delete() call from within the model to handle the fragment expiration, with the new/edited/deleted model selecting the appropriate caches to expire according to its related models. -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.