RE: [SMARTY] About caching

From: Date: Wed, 25 Dec 2002 20:53:53 +0000
Subject: RE: [SMARTY] About caching
References: 1  Groups: php.smarty.general 
Request: Send a blank email to php-smarty-general+get-6936@lists.php.net to get a copy of this message
Thanks for your reply! for 1) The problem is about the insert function is that "it's against the principes of using templates". By using templates, you want to separate code and html. But if you use the insert function, you have html into your php code? Beside that, I don't understand for 100% how the insert function works. Imagine my usersOnline() function is part of a class. If smarty looks for a usersOnline() function, how can it work? I suppose Smarty calls the function at this way: MyClass::usersOnline(). But now, the constructor of MyClass isn't called + the vars of that class aren't set + I don't have a database connection there + ... ? The insert function is a nice idea, but I don't think it's a good idea to use it for your whole site. No work-around known? for 2) I do only have one memberlist for my site and it is shown on nearly every page. With "flushing the whole cache", you mean "deleting the whole cache directory"? The timestamp is a good idea, but then I must hard-code a variabele like $lastModificationMemberList ? Thanks again, Peter -----Original Message----- From: M Mohr [mailto:messju@lammfellpuschen.de] Sent: woensdag 25 december 2002 21:24 To: Peter Billen Cc: smarty-general@lists.php.net Subject: Re: [SMARTY] About caching Hello, On Wed, Dec 25, 2002 at 08:15:40PM +0100, Peter Billen wrote: > 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. yes, smarty caches the *output* of your index.html-template, so no cache-checks are done for memberlist.html etc., when a valid cached version of index.html is found in the cache. i think, "insert" does the opposite of what you want. you want parts of your (non-cached) template to be cached. "insert" makes parts of your cached template non-cached. for 1): define an insert function that returns the html-block of your 'x users are online'-box. so everytime your cached template is delivered, the insert function is called and inserts the correct (non-cached) information about the users. for 2): if you only have one memberlist for your whole site, that does not change too often and is shown on nearly every page, then maybe flushing the whole cache, when something canges in the memberlist is a good solution for the problem. alternatively you can add a 2nd cache-group to your cache_id, so that your $cacheGroup looks like something like 'SECTION_NEWS|[timestamp]' with [timestamp] being the time when the most recent modification to your memberlist was done. HTH messju > I hope someone can help me :) Thanks! > > Peter > > > -- > Smarty General Mailing List (http://smarty.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php -- Smarty General Mailing List (http://smarty.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php

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