Re: [Radiant] Re: Possible to disable cache for a single page?
Hello Drew, Makes perfect sense! Thank you very much for taking the time to provide this explanation -- much appreciated. Cheers, Nicholas On Thu, Jun 11, 2009 at 7:44 PM, Andrew Neil wrote: > > >> This is an old thread that I have been meaning to follow up. Sean >> suggested: >> that one should focus on the _why_ you need an uncached page in the first place, and address that need first > > Indeed! > >> I created a route: >> >> map.with_options(:controller => 'site') do |site| >> site.connect 'store-directory/:name', :action => 'show_page', >> :url => '/store-directory/store' >> end >> >> This captures URL's like these: >> >> /store-directory/mcdonoughs-your-independent-grocery >> /store-directory/carlton-cards > > A better solution would be to create a new model called StorePage, > inheriting from Radiant's Page model. You can override the find_by_url > method, so that the StorePage would behave as an 'index' page, or a 'show' > page. For example: > > /store-directory > Would be an index page, listing all your stores > > /store-directory/mcdonoughs-your-independent-grocery > /store-directory/carlton-cards > These would be 'show' pages, for individual stores. > > You would only need to create a single StorePage in your Radiant sitemap. In > the above example, this would have the slug 'store-directory'. Each of the > sub-pages, corresponding to individual Store models, would exist as 'virtual > pages'. You won't see them in the sitemap of the Radiant admin, but they > exist on the public facing site. > > If you use this approach, you don't need to create any custom routes. The > index/show pages would both be rendered using the SiteController#show_page > action. This should mean that caching works just as you would expect. So the > /store-directory page and /store-directory/carlton-cards pages would be > cached without interfering with each other. > > Here is an example of a model that overrides the page model: > > > http://github.com/nelstrom/radiant-movies-extension/blob/97b149f84f75e887dd37261acdee3ebd6570b26c/app/models/movie_page.rb#L5-17 > > Note the tags: and . The content > for the index page should go inside the if_index tag, and the content for > the 'show' pages should go inside the unless_index block. > > I hope this helps clear things up. > > Cheers, > Drew > ___ > Radiant mailing list > Post: Radiant@radiantcms.org > Search: http://radiantcms.org/mailing-list/search/ > Site: http://lists.radiantcms.org/mailman/listinfo/radiant > ___ Radiant mailing list Post: Radiant@radiantcms.org Search: http://radiantcms.org/mailing-list/search/ Site: http://lists.radiantcms.org/mailman/listinfo/radiant
Re: [Radiant] Re: Possible to disable cache for a single page?
Andrew Neil wrote: A better solution would be to create a new model called StorePage, inheriting from Radiant's Page model. *snip* This belongs in the wiki!!! Cheers, Mohit. 6/14/2009 | 12:07 AM. ___ Radiant mailing list Post: Radiant@radiantcms.org Search: http://radiantcms.org/mailing-list/search/ Site: http://lists.radiantcms.org/mailman/listinfo/radiant
Re: [Radiant] Re: Possible to disable cache for a single page?
This is an old thread that I have been meaning to follow up. Sean suggested: that one should focus on the _why_ you need an uncached page in the first place, and address that need first Indeed! I created a route: map.with_options(:controller => 'site') do |site| site.connect 'store-directory/:name', :action => 'show_page', :url => '/store-directory/store' end This captures URL's like these: /store-directory/mcdonoughs-your-independent-grocery /store-directory/carlton-cards A better solution would be to create a new model called StorePage, inheriting from Radiant's Page model. You can override the find_by_url method, so that the StorePage would behave as an 'index' page, or a 'show' page. For example: /store-directory Would be an index page, listing all your stores /store-directory/mcdonoughs-your-independent-grocery /store-directory/carlton-cards These would be 'show' pages, for individual stores. You would only need to create a single StorePage in your Radiant sitemap. In the above example, this would have the slug 'store- directory'. Each of the sub-pages, corresponding to individual Store models, would exist as 'virtual pages'. You won't see them in the sitemap of the Radiant admin, but they exist on the public facing site. If you use this approach, you don't need to create any custom routes. The index/show pages would both be rendered using the SiteController#show_page action. This should mean that caching works just as you would expect. So the /store-directory page and /store- directory/carlton-cards pages would be cached without interfering with each other. Here is an example of a model that overrides the page model: http://github.com/nelstrom/radiant-movies-extension/blob/97b149f84f75e887dd37261acdee3ebd6570b26c/app/models/movie_page.rb#L5-17 Note the tags: and . The content for the index page should go inside the if_index tag, and the content for the 'show' pages should go inside the unless_index block. I hope this helps clear things up. Cheers, Drew ___ Radiant mailing list Post: Radiant@radiantcms.org Search: http://radiantcms.org/mailing-list/search/ Site: http://lists.radiantcms.org/mailman/listinfo/radiant
Re: [Radiant] Re: Possible to disable cache for a single page?
This is an old thread that I have been meaning to follow up. Sean suggested: >> that one >> should focus on the _why_ you need an uncached page in the first >> place, and address that need first I wanted to provide an example of why I needed to have a page not cached and see if there was a better way to implement this. Feel free to chime in! This is why I needed the page not to be cached: I created a store directory extension which had structured data such as store name, floor, location etc. Nothing special to this, basically the same as the "link roll" example extension. I created some custom tags to displays the store index. Again nothing special here. However, the store index linked to a store's detail page. I created a route: map.with_options(:controller => 'site') do |site| site.connect 'store-directory/:name', :action => 'show_page', :url => '/store-directory/store' end This captures URL's like these: /store-directory/mcdonoughs-your-independent-grocery /store-directory/carlton-cards This routed to a single store page which acted as my template. The name (or slug) was used to look up the store in the database. I used some tags in my store details pages which looked something like this: Website The store tag found the store by name/slug. Because I was using a single page to display the store details which would change based on the name passed in the URL, the first store that was shown would be cached and when visiting other store details, it would display the cached store, rather than the proper details. Making the store template page not cached, resolved this issue. Did I go about this the right way, or is there a better method so I can have all the store details cached as well? Any thoughts would be much appreciated! Thanks! On Tue, Aug 5, 2008 at 12:37 PM, Mohit Sindhwani wrote: > Sean Cribbs wrote: >> >> Right. The only caveat of disabling the cache is the potential for >> lower performance. However, my point in bringing that up is that one >> should focus on the _why_ you need an uncached page in the first >> place, and address that need first. For example, with comments (see >> the radiant-comments project on github from ntalbott and >> artofmission), it may not be necessary to make the page uncached >> because you can clear the cache after a comment is posted. >> > > Sean > > Thanks for the explanations. I shall try to put these into the > documentation this weekend. I think the example from the radiant-comments > extension will be very useful. I shall look it up! > > Cheers, > Mohit. > 8/6/2008 | 12:37 AM. > > ___ > Radiant mailing list > Post: Radiant@radiantcms.org > Search: http://radiantcms.org/mailing-list/search/ > Site: http://lists.radiantcms.org/mailman/listinfo/radiant > ___ Radiant mailing list Post: Radiant@radiantcms.org Search: http://radiantcms.org/mailing-list/search/ Site: http://lists.radiantcms.org/mailman/listinfo/radiant
Re: [Radiant] Re: Possible to disable cache for a single page?
Sean Cribbs wrote: Right. The only caveat of disabling the cache is the potential for lower performance. However, my point in bringing that up is that one should focus on the _why_ you need an uncached page in the first place, and address that need first. For example, with comments (see the radiant-comments project on github from ntalbott and artofmission), it may not be necessary to make the page uncached because you can clear the cache after a comment is posted. Sean Thanks for the explanations. I shall try to put these into the documentation this weekend. I think the example from the radiant-comments extension will be very useful. I shall look it up! Cheers, Mohit. 8/6/2008 | 12:37 AM. ___ Radiant mailing list Post: Radiant@radiantcms.org Search: http://radiantcms.org/mailing-list/search/ Site: http://lists.radiantcms.org/mailman/listinfo/radiant
Re: [Radiant] Re: Possible to disable cache for a single page?
> I'm just thinking of putting this down as the starting point for one of the > pages in the 'Summer Reboot' but I have a couple of questions to understand > this slightly better: > 1. Where would that code go? How does one go about creating a page subclass > - from there on, it's easy. That would go in app/models of an extension, preferably. > > 2. What would be an example of a greater functional need from the system? > > I'm guessing comments fields and some other dynamic pages would need this > functionality. What should someone be careful of in disabling the cache for > a page? Right. The only caveat of disabling the cache is the potential for lower performance. However, my point in bringing that up is that one should focus on the _why_ you need an uncached page in the first place, and address that need first. For example, with comments (see the radiant-comments project on github from ntalbott and artofmission), it may not be necessary to make the page uncached because you can clear the cache after a comment is posted. Sean ___ Radiant mailing list Post: Radiant@radiantcms.org Search: http://radiantcms.org/mailing-list/search/ Site: http://lists.radiantcms.org/mailman/listinfo/radiant
Re: [Radiant] Re: Possible to disable cache for a single page?
Hi Sean Sean Cribbs wrote: The typical solution is to make a page subclass that adds this method: def cache? false end I'm just thinking of putting this down as the starting point for one of the pages in the 'Summer Reboot' but I have a couple of questions to understand this slightly better: 1. Where would that code go? How does one go about creating a page subclass - from there on, it's easy. Then make the page that you want uncached to be of that type. Before you do that, however, take into consideration why you need the page uncached. It may be that the need for it to be uncached is secondary to a greater functional need from the system, and that that should be addressed first. 2. What would be an example of a greater functional need from the system? I'm guessing comments fields and some other dynamic pages would need this functionality. What should someone be careful of in disabling the cache for a page? Thanks Mohit. ___ Radiant mailing list Post: Radiant@radiantcms.org Search: http://radiantcms.org/mailing-list/search/ Site: http://lists.radiantcms.org/mailman/listinfo/radiant
Re: [Radiant] Re: Possible to disable cache for a single page?
The typical solution is to make a page subclass that adds this method: def cache? false end Then make the page that you want uncached to be of that type. Before you do that, however, take into consideration why you need the page uncached. It may be that the need for it to be uncached is secondary to a greater functional need from the system, and that that should be addressed first. Sean On Mon, Aug 4, 2008 at 3:29 PM, Nicholas Henry <[EMAIL PROTECTED]> wrote: > I'm doing some similar and would love to know how to achieve this! > -- > Posted via http://www.ruby-forum.com/. > ___ > Radiant mailing list > Post: Radiant@radiantcms.org > Search: http://radiantcms.org/mailing-list/search/ > Site: http://lists.radiantcms.org/mailman/listinfo/radiant > ___ Radiant mailing list Post: Radiant@radiantcms.org Search: http://radiantcms.org/mailing-list/search/ Site: http://lists.radiantcms.org/mailman/listinfo/radiant