Smarty cached files invalidation
I'd like to go slightly deeper into Smarty caching, so I have some simple questions...
To manipulate cache invalidation I want to know what directory Smarty is storing it's cache in. For example, all c开发者_C百科ached pages related to
user_id=123
I want to store atcache/users/123/
. Wherecache
is smarty caching dir. How can I tell smarty to store cache related touser_id=123
atcache/users/123/
? Will Smarty store cache of sub-templates in this directory also?Is there any recommendations about cleaning cache in this directory? I think that simply removing files from this directory can cause some errors if some visitors are currently visiting this pages (Error can occure when smarty will see that template cache is found, but sub-template cache isn't found because it was already removed, for example).
Any recommendations and advices are appreciated.
Thank you.
You should NOT clear cache manually. Use clear_cache() and clear_compiled_tpl() for that. You can clear all cache and also do selective clearing with them.
Take a look at the Smarty docs: the "Cache Groups" section. Does exactly that.
Use can switch the smarty cachedir, depending on where you want is (you can check that with some own if-statements)
// Create smarty object
$smarty = new Smarty();
// Change smarty-dir is like this:
if (isset($_GET['userId'])) {
$smarty->compile_dir = '/path/to/dir/' . $_GET['userId'];
} else {
$smarty->compile_dir = '/path/to/dir/default';
}
Point two is a little harder, you have to foreach through all mapps, and assign the new compile dir, and then run the following command:
$smarty->clear_cache();
But as you said, it's possible the file is requested while there is a remove. :-(
But it's not recommended to use different cache folders, Smarty doesn't cache the output, just the compiled PHP-file.
精彩评论