Categories > TinyButStrong general >

How to detected template changes and update the cache?

The forum is closed. Please use Stack Overflow for submitting new questions. Use tags: tinybutstrong , opentbs
By: testebr
Date: 2007-03-02
Time: 14:28

How to detected template changes and update the cache?

Hi,

I changed an template file now, but my page still with old content/layout because my cache file dont updated. I need always wait xx minutes (defined in TBS_CACHE function) to see the new content.

How to make my php detect the changes in template file and update the cache?

remember, template file and not data from db or like it.
By: TomH
Date: 2007-03-02
Time: 16:21

Re: How to detected template changes and update the cache?

Not sure why you don't know which cache to delete, or why ypu want to do this as part of your PHP code, but...
assuming that you DO want to include php code for this in your files (which is a big question :)...

(1) you would need to have a fixed method of setting your $cacheid filename that depends upon the template filename so that you have access to it in your php file. I always name template file same as php file but with different extension -- you could do same for naming the cache file, something like this...
$tpl_name = basename($_SERVER['SCRIPT_NAME'], ".php").".html") ;
$cacheid  = basename($_SERVER['SCRIPT_NAME'], ".php").".cache") ;

(2) now you can test the 'age' of the template file and delete (unlink) the cachefile, something like this... UNTESTED...
$tpl_age = 3 ;  // if newer than 3 minutes then will delete cache file
$fileage = round( ( time() - filemtime("$tpl_name") )/60 );
if( $fileage < $tpl_age ) {
unlink("$cacheid");
}

Hope that helps a little,
TomH
By: TomH
Date: 2007-03-02
Time: 23:48

Re: How to detected template changes and update the cache?

Ooops, should have been
$tpl_name = basename($_SERVER['SCRIPT_NAME'], ".php").".html";
$cacheid  = basename($_SERVER['SCRIPT_NAME'], ".php").".cache";
By: testebr
Date: 2007-03-05
Time: 20:19

Re: How to detected template changes and update the cache?

I liked the method 2, but I dont understand why this feature not is present by default in the class.

I have an crucial question: would not this resource be important for the developer? Will we suppose that I define a cache time of one hour, would I have then to await this whole time to see the change of the layout?  Or do you recommend that I delete the cache manually? True?

I'm not pro in php, my question sound like an noob, but I really dont understand it.

I would like to receive all possible explanation about it.
By: sheepy
Date: 2007-03-17
Time: 01:39

Re: How to detected template changes and update the cache?

Maybe because data is much more likely to be updated then template?  Hell, my latest system now has to read template from database - "everything must be CMS controlled with WYSIWYG" - so when I check for template update time I need to send over a query...