Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

caching of same variable name

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Feature Requests
View previous topic :: View next topic  
Author Message
jainarpitr
Smarty n00b


Joined: 07 Jul 2014
Posts: 2

PostPosted: Mon Jul 07, 2014 8:41 am    Post subject: caching of same variable name Reply with quote

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
View user's profile Send private message
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7368
Location: Lincoln Nebraska, USA

PostPosted: Mon Jul 07, 2014 4:03 pm    Post subject: Reply with quote

I believe in Smarty 3 you can simply do:

Code:
{include file=$middle nocache}
Back to top
View user's profile Send private message Visit poster's website
jainarpitr
Smarty n00b


Joined: 07 Jul 2014
Posts: 2

PostPosted: Mon Jul 07, 2014 7:08 pm    Post subject: Reply with quote

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
View user's profile Send private message
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7368
Location: Lincoln Nebraska, USA

PostPosted: Tue Jul 08, 2014 3:28 am    Post subject: Reply with quote

For each unique page, set a unique cache_id. This could be URL based, or whatever determines uniqueness for a page.

See example 15.6

http://www.smarty.net/docs/en/caching.multiple.caches.tpl
Back to top
View user's profile Send private message Visit poster's website
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1785

PostPosted: Mon Jul 14, 2014 9:03 pm    Post subject: Reply with quote

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
View user's profile Send private message
U.Tews
Administrator


Joined: 22 Nov 2006
Posts: 5068
Location: Hamburg / Germany

PostPosted: Tue Jul 15, 2014 2:30 am    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Feature Requests All times are GMT
Page 1 of 1

 
Jump to:  
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
Protected by Anti-Spam ACP