|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
jainarpitr Smarty n00b
Joined: 07 Jul 2014 Posts: 2
|
Posted: Mon Jul 07, 2014 8:41 am Post subject: caching of same variable name |
|
|
I have index.htm file like this
Code: | {include file=$top}
{include file=$left}
{include file=$middle}
{include file=$bottom} |
The top, left and bottom variables are almost constant everytime. But the middle variable changes with each different page.
I want to cache this, using memcache, but smarty always shows the same middle page which is cached thereafter.
Can this be resolved anyhow? |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Mon Jul 07, 2014 4:03 pm Post subject: |
|
|
I believe in Smarty 3 you can simply do:
Code: | {include file=$middle nocache} |
|
|
Back to top |
|
jainarpitr Smarty n00b
Joined: 07 Jul 2014 Posts: 2
|
Posted: Mon Jul 07, 2014 7:08 pm Post subject: |
|
|
But the point is that middle is the main content.. There will be hardly any use of cache if i leave the middle uncached.. |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
|
Back to top |
|
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
Posted: Mon Jul 14, 2014 9:03 pm Post subject: |
|
|
Good idea is to use page identifier as cache_id to cache page main content.
It can be anything, from distinctive article id to complete URL path of the page, the only characteristics necessary is that cache_id is readily available, persistent and directly relevant to the cached content.
I.e., I'm using section_id as cache_id when caching a tree-like catalog sections structure. (Each "section selected" uniquely identify the displayed structure, and it is in fact part of the query, so it is readily available, and distinctive by the definition of uniqueness.) Takes hell of a lot of time to query and render, but, once cached, it is displayed near-instantly. |
|
Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Tue Jul 15, 2014 2:30 am Post subject: |
|
|
Assign the template name as a no cache variable.
Code: | $smarty->assign('middle','foo.tpl',true); |
In the template force a seperate cache file for the subtemplate
Code: | {include file=$middle caching} |
Now the middle template has it's own cache file which will be included dynamicly in the cached index file |
|
Back to top |
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|