Re: [SMARTY] cache date and time

From: Date: Wed, 05 Jun 2002 14:53:51 +0000
Subject: Re: [SMARTY] cache date and time
References: 1 2 3  Groups: php.smarty.dev php.smarty.general 
Request: Send a blank email to php-smarty-dev+get-115@lists.php.net to get a copy of this message
I've toyed around with the idea of adding $group_id in the past, but this just makes thing way too complicated, we already have cache_id and compile_id. What if we were able to clear caches based cache_id? Could this be used conceptually as a group id? Here is how the cache filenames are generated (currently): The template resource name is used to create the top level directory and sub level directory. So lets say our template resource is named "index.tpl", which would get hashed into "1172603085" So all cached files for "index.tpl" would reside under this directory (in the $cache_dir): /117/1172603085/ So now you see, we can remove all cache files based on the template resource name. Notice that with a subdirectory structure we just delete a directory, no regular expression work on filenames is necessary. The cache filename itself is generated from a combination of the cache_id and compile_id. If both of these are null, the result is zero. /117/1172603085/0.php |--------------|-------------------| resource name cache_id/compile_id If cache_id or compile_id have a value, these are hashed together and a filename is generated. /117/1172603085/4444455555.php |--------------|-------------------| resource name cache_id/compile_id So in Smarty's current form, there is no way to remove cache files based on cache_id or compile_id. However, we could make a slight change to the way the file structure is created. We could hash the cache_id and compile_id separately, and end up with something like this: /117/1172603085/4444455555/6666677777.php |--------------|----------|-------------| resource name cache_id compile_id So now we can use template resource and cache_id combined to removed groups of caches. Now the last issue: what if we wanted to remove caches based on cache_id alone, so we can group different template resources together? We could swap things around like this: /4444455555/117/1172603085/6666677777.php |----------|--------------|-------------| cache_id resource name compile_id We can still remove caches by resource name alone, it would just have a cache_id of null. In the majority of cases cache_id would be null so 99% of your templates would be under the root directory /0/, which really isn't a big deal IMHO. Thoughts? Monte Ivo Jansch wrote:
Hi, Monte Ohrt wrote:
How would you get the cache id? You need that to get the cache in the first place.
Maybe there should be 2 id's. Think of this situation: Suppose in a site, I have several pages, each of which uses the same template (say page.tpl) . Each page is identified by some id (I'll call it a page_id for now). On some pages, there are some dynamic elements, whose output depends on variables passed through the url (showpage.php?page_id=10&newsitem=20 etc.) So my cache_id for page.tpl is based on the page_id and the url variables. So far so good, this is already possible in Smarty. But now I change the content of the page with page_id 20. I need to be able to tell the cache: delete all cached pages that are based on page_id 20 (so different cache_id's, but the same page_id). So actually, I should be able to 'group' cached versions of a page based on something (in this case, we group all cached pages that have the same page_id). Cache management could then have the following features: 1) expire after a certain ammount of time (current implementation) 2) expire cached page with a certain cache_id (new) 3) expire group of cached pages with a certain page_id (new) I think this would be useful in more than a few occasions. A lot of Smarty applications contain content management systems that could use method 2 and 3. Greetings, Ivo
-- Monte Ohrt <monte@ispi.net> Director of Technology, ispi Inc.

« previous php.smarty.dev (#115) next »