Smarty cache with database content error

I use smarty's caching function, and today I understand that my content has not been updated correctly.

I use smarty file caching with these templates:

  • index.html (use this to cache the main page (about 8k)
  • list.html (use this to cache about 10 pages - about 7 thousand each)

I have custom cms, and this allows me to change the main page, which it does not refresh, I use:

cache_dir and cache check is correct, because if I delete the cache file, I can see that my content is updated.

Is there an easy way to refresh these files without deleting them every time I refresh the contents of the page?

+4
source share
2 answers

you can use this:

$Smarty = new Smarty(); $Smarty->caching = 1; $SmartyTemplate = $Smarty->createTemplate($yourfile, $your_cache_id); // $row = mysql_query("select date_modified from table where ... if ($SmartyTemplate->isCached() && $SmartyTemplate->cached->timestamp < $row['date_modified']) { $Smarty->clearCache($yourfile, $your_cache_id); } $SmartyTemplate->assign('variables', 'data'); $SmartyTemplate->display(); 
+4
source

Here you have two options.

1) When you update something about index.html or list.html, tell Smarty to clear the corresponding cache using $smarty->clearCache("index.html"); See documents .

2) Write your own CacheResource . Then you can overload the fetch () and fetchTimestamp () methods to additionally query some database for external modification time. This way you do not need clearCache() inform Smarty that something has changed.

The first option is easier and faster to implement. The second option is a global thing, potentially wasting resources on additional connections to the database.

+1
source

Source: https://habr.com/ru/post/1398014/


All Articles