smarty中删除缓存的方法
来源:互联网 发布:淘宝仓库管理流程 编辑:程序博客网 时间:2024/05/22 02:21
同时,smarty也提供了一个清除缓存的function(实质是使缓存文件过期,并非删除缓存文件)
我们发现可以使用:
- function clear_cache($tpl_file = null, $cache_id = null, $compile_id = null, $exp_time = null)删除某个具体的模板。如主页,某条信息。
- function clear_all_cache($exp_time = null)删除缓存目录下所有所有缓存信息。
然而很多人,也包括我,一开始对怎么清理所有内容页(即show.php?id=1 .... 198 ....)的所有缓存文件产生了疑问。clear_cache()显然不适用,而clear_all_cache呢?似乎后者会把index.php等其它页面的缓存文件也清除。
在这里提提大家,看到我对function clear_all_cache()划线部分的标注。 clear_all_cache是把缓存目录下的所有文件清理掉。所以如果我们把show.php?id=1....134...的缓存文件都放在一个show的目录下,在执行clear_all_cache的时候,先设置cache_dir的路径为show,似乎一切就可行了,而事实上也是这样。
如我在项目中的一个使用:
渲染模板到show目录下:
- <?php
- header("HTTP/1.0 200 OK");
- require_once 'includes/common.php';
- $smarty = new CustomSmarty();
- $smarty->cache_dir = $smarty->cache_dir."/show";
- $smarty->caching = true;
- $key = $_GET['key'];
- if(!$smarty->is_cached('page.html',$key))
- {
- #code here
- }
- $smarty->display('page.html',$key);
- ?>
清理show目录下的缓存:
- <?php
- require_once dirname(__FILE__).'/../../includes/common.php';
- $smarty = new CustomSmarty();
- $smarty->caching = false;
- $smarty->cache_dir = $smarty->cache_dir."/show";
- $smarty->clear_all_cache();
- $smarty->assign("title","更新内容页缓存");
- $smarty->display("admin/recache/index.html");
- ?>
- smarty中删除缓存的方法
- smarty缓存的删除
- php smarty 删除缓存
- 设置Smarty中缓存的生存时间
- Smarty的缓存操作
- Smarty缓存的学习
- smarty缓存的应用
- smarty的局部缓存
- smarty模板局部缓存方法
- Smarty中局部不缓存
- smarty应用中fckeditor的方法
- Smarty中批量生成html的方法
- 删除weblogic应用缓存,weblogic 缓存的删除方法
- php+Smarty的缓存操作
- Smarty的缓存操作技巧
- smarty的局部区域缓存
- Smarty的缓存操作技巧
- Smarty的缓存操作技巧
- SQLServer2008数据引擎连接问题
- JavaScript实现页面跳转的几种方式
- 目前最经典的关于虚函数的解释整理
- poj 2388
- 阿里旺旺Linux版
- smarty中删除缓存的方法
- 预言成真:Facebook拿浏览器开刀 推进移动化进程
- 生产tornado所需的cookie_secret的方法
- uboot启动参数设置分类及方法
- 去掉FriendlyARM
- 将一个int数值转化成字符串 - itoa(...) - strlen(...)
- windows核心编程,结构化异常部分,理解摘要
- 常用的MySQL数据库命令大全
- mysql数据库优化总结(转载加自己的总结)