Hi, I have a sidebar on a web page that I want to put into a cache fragment. Are cache fragments specific to the controller that invoked the view? Or can I use the cache fragment on other views that were invoked via a different controller. So If I do: <% cache(:part => "currenttime") do %> <%= Time.now %> <% end %> Can I access the cache fragment as "currenttime" from any view? ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~Scott F. Walterscottwalter.com --explorer what''s new
On 11/3/05, Scott Walter <tx_scottwalter-/E1597aS9LQAvxtiuMwx3w@public.gmane.org> wrote:> Hi, > > I have a sidebar on a web page that I want to put into > a cache fragment. Are cache fragments specific to the > controller that invoked the view? Or can I use the > cache fragment on other views that were invoked via a > different controller. > > So If I do: > > <% cache(:part => "currenttime") do %> > <%= Time.now %> > <% end %> > > Can I access the cache fragment as "currenttime" from > any view? >Check the docs on fragment caching: http://rails.rubyonrails.com/classes/ActionController/Caching/Fragments.html I don''t believe yours will be accessible from other controllers/actions, because it uses the current URL to name the fragment. Solution: pass in your own controller/action. <% cache :controller => ''foo'', :action => ''bar'' do %> -- rick http://techno-weenie.net
hi scott, the controller is set implicit. the complete key used for the cache is build via url_for(). you can see it in the production.log, e.g.: Fragment hit: localhost:3000/news/list?part=top_news Am 03.11.2005 um 16:42 schrieb Scott Walter:> Hi, > > I have a sidebar on a web page that I want to put into > a cache fragment. Are cache fragments specific to the > controller that invoked the view? Or can I use the > cache fragment on other views that were invoked via a > different controller. > > So If I do: > > <% cache(:part => "currenttime") do %> > <%= Time.now %> > <% end %> > > Can I access the cache fragment as "currenttime" from > any view? > > > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~Scott F. > Walterscottwalter.com --explorer what''s new > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails > >--- Thomas Baustert - Freiberuflicher Softwarecoach fon: +49(40)411 622 35 mobil: +49(173)23 911 43 fax: +49(40)411 622 36 thomas.baustert-95+UFKxf6Ncb1SvskN2V4Q@public.gmane.org