Smarty 缓存文件失效

发布于 2024-09-14 05:01:52 字数 488 浏览 4 评论 0原文

我想更深入地了解 Smarty 缓存,所以我有一些简单的问题...

  1. 为了操纵缓存失效,我想知道 Smarty 将其缓存存储在哪个目录中。例如,与 < 相关的所有缓存页面code>user_id=123 我想存储在cache/users/123/。其中 cache 是 smarty 缓存目录。如何告诉 smarty 将与 user_id=123 相关的缓存存储在 cache/user/123/ 中? Smarty 是否也会在此目录中存储子模板的缓存?

  2. 有关于清理此目录中缓存的任何建议吗?我认为,如果某些访问者当前正在访问此页面,则简单地从该目录中删除文件可能会导致一些错误(当 smarty 看到找到模板缓存,但找不到子模板缓存,因为它已被删除时,可能会发生错误,例如)。

如有任何建议和意见,我们将不胜感激。

谢谢。

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

怼怹恏 2024-09-21 05:01:52

您不应该手动清除缓存。为此,请使用clear_cache() 和clear_compiled_tpl()。您可以清除所有缓存,也可以对它们进行选择性清除。

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.

霊感 2024-09-21 05:01:52

查看 Smarty 文档:“缓存组”部分。正是这样做的。

Take a look at the Smarty docs: the "Cache Groups" section. Does exactly that.

满地尘埃落定 2024-09-21 05:01:52

使用可以切换 smarty 缓存目录,具体取决于您想要的位置(您可以使用一些自己的 if 语句进行检查)

// 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';
}

第二点有点困难,您必须遍历所有映射,并分配新的编译目录,然后运行以下命令:

$smarty->clear_cache();

但正如您所说,有可能在删除时请求该文件。 :-(


但是不建议使用不同的缓存文件夹,Smarty 不缓存输出,只缓存编译后的 PHP 文件。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文