I noticed a lot of repetition across different Sweeper models in my app expiring the same fragments and so have been trying to move all the expire_fragment calls into another model which the sweepers can then use but it''s not working as I''d hoped.. I''ve created a CacheDestroyer model and want to be able to call something to the effect of: CacheDestroyer.clear_all_page_relations but I''m struggling to find how to make the "expire_fragment" method available to this model. I''ve tried putting "include ActionController::Caching::Fragments" in the CacheDestroyer model but it doesn''t seem to be working (undefined method `expire_fragment'' for CacheDestroyer:Class (NoMethodError)) Any ideas how I can get the "expire_fragment" method to be available to this model? Thanks in advance for any help, Damien --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
The problem with trying to access what the controller did/does [caching and sweeping the cache] from the model is that it breaks one of Rails'' philosophies: MVC [the separation of model - view - controller code]. The proper solution is to use Sweeper classes. There''s a good bit of information out there on these as well. The guys over at RailsEnvy have a good tutorial you might want to check out: http://www.railsenvy.com/2007/3/20/ruby-on-rails-caching-tutorial-part-2. Hope that helps, RSL On 10/21/07, idleFingers <mail-SuwyNEombvosXMjTw6Upulpr/1R2p/CL@public.gmane.org> wrote:> > I noticed a lot of repetition across different Sweeper models in my > app expiring the same fragments and so have been trying to move all > the expire_fragment calls into another model which the sweepers can > then use but it''s not working as I''d hoped.. > > I''ve created a CacheDestroyer model and want to be able to call > something to the effect of: CacheDestroyer.clear_all_page_relations > but I''m struggling to find how to make the "expire_fragment" method > available to this model. > > I''ve tried putting "include ActionController::Caching::Fragments" in > the CacheDestroyer model but it doesn''t seem to be working (undefined > method `expire_fragment'' for CacheDestroyer:Class (NoMethodError)) > > Any ideas how I can get the "expire_fragment" method to be available > to this model? > > Thanks in advance for any help, > Damien > > > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Thanks Russell. I am already using sweepers however. What I can''t get to work is to refactor repetitive code from multiple sweepers into one common model which can then be referenced from each sweeper. It doesn''t have to be a model really, I''m just trying to clean my code up! For example, in my app, I have some active record models; Location, Page, Talent. Each has a sweeper to expire caches but there''s a lot of repetition between those three sweepers. I can''t combine them into one sweeper because they''re slightly different but I don''t want to keep copying & pasting the same expire_fragment snippets from one to the other.. seems so un-rails like. On Oct 21, 12:59 pm, "Russell Norris" <r...-ftMzyaTR+bHNyFkoKTPOtdi2O/JbrIOy@public.gmane.org> wrote:> The problem with trying to access what the controller did/does > [caching and sweeping the cache] from the model is that it breaks one > of Rails'' philosophies: MVC [the separation of model - view - > controller code]. The proper solution is to use Sweeper classes. > There''s a good bit of information out there on these as well. The guys > over at RailsEnvy have a good tutorial you might want to check out:http://www.railsenvy.com/2007/3/20/ruby-on-rails-caching-tutorial-part-2. > Hope that helps, > > RSL > > On 10/21/07, idleFingers <m...-SuwyNEombvosXMjTw6Upulpr/1R2p/CL@public.gmane.org> wrote: > > > > > I noticed a lot of repetition across different Sweeper models in my > > app expiring the same fragments and so have been trying to move all > > the expire_fragment calls into another model which the sweepers can > > then use but it''s not working as I''d hoped.. > > > I''ve created a CacheDestroyer model and want to be able to call > > something to the effect of: CacheDestroyer.clear_all_page_relations > > but I''m struggling to find how to make the "expire_fragment" method > > available to this model. > > > I''ve tried putting "include ActionController::Caching::Fragments" in > > the CacheDestroyer model but it doesn''t seem to be working (undefined > > method `expire_fragment'' for CacheDestroyer:Class (NoMethodError)) > > > Any ideas how I can get the "expire_fragment" method to be available > > to this model? > > > Thanks in advance for any help, > > Damien--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
What I''d do is create a module for that shared functionality and mix it in to the sweepers. RSL On 10/21/07, idleFingers <mail-SuwyNEombvosXMjTw6Upulpr/1R2p/CL@public.gmane.org> wrote:> > Thanks Russell. I am already using sweepers however. What I can''t get > to work is to refactor repetitive code from multiple sweepers into one > common model which can then be referenced from each sweeper. It > doesn''t have to be a model really, I''m just trying to clean my code > up! > > For example, in my app, I have some active record models; Location, > Page, Talent. Each has a sweeper to expire caches but there''s a lot of > repetition between those three sweepers. I can''t combine them into one > sweeper because they''re slightly different but I don''t want to keep > copying & pasting the same expire_fragment snippets from one to the > other.. seems so un-rails like. > > On Oct 21, 12:59 pm, "Russell Norris" <r...-ftMzyaTR+bHNyFkoKTPOtdi2O/JbrIOy@public.gmane.org> wrote: > > The problem with trying to access what the controller did/does > > [caching and sweeping the cache] from the model is that it breaks one > > of Rails'' philosophies: MVC [the separation of model - view - > > controller code]. The proper solution is to use Sweeper classes. > > There''s a good bit of information out there on these as well. The guys > > over at RailsEnvy have a good tutorial you might want to check out:http://www.railsenvy.com/2007/3/20/ruby-on-rails-caching-tutorial-part-2. > > Hope that helps, > > > > RSL > > > > On 10/21/07, idleFingers <m...-SuwyNEombvosXMjTw6Upulpr/1R2p/CL@public.gmane.org> wrote: > > > > > > > > > I noticed a lot of repetition across different Sweeper models in my > > > app expiring the same fragments and so have been trying to move all > > > the expire_fragment calls into another model which the sweepers can > > > then use but it''s not working as I''d hoped.. > > > > > I''ve created a CacheDestroyer model and want to be able to call > > > something to the effect of: CacheDestroyer.clear_all_page_relations > > > but I''m struggling to find how to make the "expire_fragment" method > > > available to this model. > > > > > I''ve tried putting "include ActionController::Caching::Fragments" in > > > the CacheDestroyer model but it doesn''t seem to be working (undefined > > > method `expire_fragment'' for CacheDestroyer:Class (NoMethodError)) > > > > > Any ideas how I can get the "expire_fragment" method to be available > > > to this model? > > > > > Thanks in advance for any help, > > > Damien > > > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Ahhh, that sorted it.. Cheers for the help Russell. On Oct 21, 4:26 pm, "Russell Norris" <r...-ftMzyaTR+bHNyFkoKTPOtdi2O/JbrIOy@public.gmane.org> wrote:> What I''d do is create a module for that shared functionality and mix > it in to the sweepers. > > RSL > > On 10/21/07, idleFingers <m...-SuwyNEombvosXMjTw6Upulpr/1R2p/CL@public.gmane.org> wrote: > > > > > Thanks Russell. I am already using sweepers however. What I can''t get > > to work is to refactor repetitive code from multiple sweepers into one > > common model which can then be referenced from each sweeper. It > > doesn''t have to be a model really, I''m just trying to clean my code > > up! > > > For example, in my app, I have some active record models; Location, > > Page, Talent. Each has a sweeper to expire caches but there''s a lot of > > repetition between those three sweepers. I can''t combine them into one > > sweeper because they''re slightly different but I don''t want to keep > > copying & pasting the same expire_fragment snippets from one to the > > other.. seems so un-rails like. > > > On Oct 21, 12:59 pm, "Russell Norris" <r...-ftMzyaTR+bHNyFkoKTPOtdi2O/JbrIOy@public.gmane.org> wrote: > > > The problem with trying to access what the controller did/does > > > [caching and sweeping the cache] from the model is that it breaks one > > > of Rails'' philosophies: MVC [the separation of model - view - > > > controller code]. The proper solution is to use Sweeper classes. > > > There''s a good bit of information out there on these as well. The guys > > > over at RailsEnvy have a good tutorial you might want to check out:http://www.railsenvy.com/2007/3/20/ruby-on-rails-caching-tutorial-part-2. > > > Hope that helps, > > > > RSL > > > > On 10/21/07, idleFingers <m...-SuwyNEombvosXMjTw6Upulpr/1R2p/CL@public.gmane.org> wrote: > > > > > I noticed a lot of repetition across different Sweeper models in my > > > > app expiring the same fragments and so have been trying to move all > > > > the expire_fragment calls into another model which the sweepers can > > > > then use but it''s not working as I''d hoped.. > > > > > I''ve created a CacheDestroyer model and want to be able to call > > > > something to the effect of: CacheDestroyer.clear_all_page_relations > > > > but I''m struggling to find how to make the "expire_fragment" method > > > > available to this model. > > > > > I''ve tried putting "include ActionController::Caching::Fragments" in > > > > the CacheDestroyer model but it doesn''t seem to be working (undefined > > > > method `expire_fragment'' for CacheDestroyer:Class (NoMethodError)) > > > > > Any ideas how I can get the "expire_fragment" method to be available > > > > to this model? > > > > > Thanks in advance for any help, > > > > Damien--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---