问题描述
假设我有一个包含动态内容(例如搜索结果)的页面.什么是正确的缓存技术?
Say I have a page that contains dynamic content (e.g. search results). What is the proper caching technique?
- 在整个页面周围放置
nocache
标签? - 在实际包含动态数据的标记段周围放置
nocache
标签? - 在动态数据周围放置
nocache
标签? - 以某种方式告诉 Smarty 不要缓存动态数据?
- Put
nocache
tags around the entire page? - Put
nocache
tags around the segment of mark up that actually contains the dynamic data? - Put
nocache
tags around the dynamic data? - Somehow tell Smarty not to cache the dynamic data?
动态数据被分配为 Smarty 变量(例如通过 assign
).我想我需要尝试最大化缓存,但我在需要缓存的内容、如何取消缓存、何时缓存、何时取消缓存等方面有些挣扎.
The dynamic data is assigned as a Smarty variable (e.g. via assign
). I think I need to try to maximize caching, but am struggling a bit at what needs to be cached, how to un-cache, when to cache, when to un-cache, etc.
有什么建议吗?
推荐答案
如果您的网站大部分是静态的,那么在显示动态内容的整个代码段周围放置 nocache
标签.
If your website is mostly static, then put nocache
tag around the entire segment of code that displays the dynamic content.
相反,如果您网站的每个页面都包含一些动态输出,我建议您在 Smarty 类初始化期间禁用 Smarty 缓存.
Instead, if every page of your website contains a bit of dynamic output, I suggest you to disable Smarty caching during Smarty class initialization.
这篇关于Smarty:如何正确缓存?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!