About caching

From: Date: Wed, 25 Dec 2002 19:15:40 +0000
Subject: About caching
Groups: php.smarty.general 
Request: Send a blank email to php-smarty-general+get-6934@lists.php.net to get a copy of this message
Hi all, First of all: merry chrismas to all of you! I hope you'll have a nice dinner tonight ;) I have a question about caching. I've read the caching section (in the manual) twice, but I couldn't find an answer on my question. My whole site is based on 1 template file: index.html. In that index.html, I have construction like: ... <table ...> {if $smarty.get.section eq "news"} {include file="v1/news.html"} {elseif ...} </table> ... So actually, by using the include function, I have several index.html files. Now I wanted to enable caching on index.html, but separated for each situation (in this example only the news-situation). In my PHP code I wrote the following code: switch ($_GET['section']) { case SECTION_NEWS: require_once("news.php"); $cacheGroup = SECTION_NEWS; /* to separate each situation! */ if (!$GLOBALS['SMARTY']->checkCached($cacheGroup)) /* = is_cached("news.html", $cacheGroup) smarty function */ showNews(); break; case ... } ... /* display whole site */ $GLOBALS['SMARTY']->display("v1/index.html", $cacheGroup); Now I can easily set cache_lifetime to -1, and only delete the cached files when an UPDATE, INSERT or DELETE sql function is called (thanks to the $cacheGroup var, I don't need to delete the whole cache directory. I can only delete the files which are really changed). This works perfect. However, I have 2 problems about this way of working with caching. I hope someone can help me out with this. 1) What if your cached page exists of contents that can change every second (so if you don't want to cache the whole template, but only some blocks of it)? Imagine you have a "who is online" tracker on your site. If your index.html is cached, the "who is online" tracker will not be "refreshed" on each click? I can't find a good solution to this problem. 2) Imagine that you have a "member list" on each (!) page (-> on each cached index.html). If you add a new member to the database, you have to delete ALL (!!!) cached files, since every cached page still contain the old member list. How do you deal with such situations? I think the real question is: how can I enable caching on BLOCKS of a template file, and not on a whole template file? I've read about the "insert" function, but I don't see how It can be used in those 2 situations. I've already tried splitting up my index.html into several template files (such as memberlist.html, who-is-online.html) and including them into my index.html. But it seems Smarty still caches them as a whole, and not as separated files. I hope someone can help me :) Thanks! Peter

« previous php.smarty.general (#6934) next »