Smarty 缓存文件失效
我想更深入地了解 Smarty 缓存,所以我有一些简单的问题...
为了操纵缓存失效,我想知道 Smarty 将其缓存存储在哪个目录中。例如,与 < 相关的所有缓存页面code>user_id=123 我想存储在
cache/users/123/
。其中cache
是 smarty 缓存目录。如何告诉 smarty 将与user_id=123
相关的缓存存储在cache/user/123/
中? Smarty 是否也会在此目录中存储子模板的缓存?有关于清理此目录中缓存的任何建议吗?我认为,如果某些访问者当前正在访问此页面,则简单地从该目录中删除文件可能会导致一些错误(当 smarty 看到找到模板缓存,但找不到子模板缓存,因为它已被删除时,可能会发生错误,例如)。
如有任何建议和意见,我们将不胜感激。
谢谢。
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 cached 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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您不应该不手动清除缓存。为此,请使用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.
查看 Smarty 文档:“缓存组”部分。正是这样做的。
Take a look at the Smarty docs: the "Cache Groups" section. Does exactly that.
使用可以切换 smarty 缓存目录,具体取决于您想要的位置(您可以使用一些自己的 if 语句进行检查)
第二点有点困难,您必须遍历所有映射,并分配新的编译目录,然后运行以下命令:
但正如您所说,有可能在删除时请求该文件。 :-(
但是不建议使用不同的缓存文件夹,Smarty 不缓存输出,只缓存编译后的 PHP 文件。
Use can switch the smarty cachedir, depending on where you want is (you can check that with some own if-statements)
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:
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.