开发者

Smarty cached files invalidation

开发者 https://www.devze.com 2023-01-10 18:50 出处:网络
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,

I'd like to go slightly deeper into Smarty caching, so I have some simple questions...

  1. 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 at cache/users/123/. Where cache is smarty caching dir. How can I tell smarty to store cache related to user_id=123 at cache/users/123/? Will Smarty store cache of sub-templates in this directory also?

  2. 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号