smarty 3.1删除指定缓存

aoyunhuowa 2013-06-09 11:22:26
使用了php的模板引擎,smarty3.1.13。smarty中删除缓存的方法:clearAllCache方法删除当前缓存目录下的所有缓存,这个是可以用的,clearCache方法删除指定的缓存,却怎么也不起作用,返回值总是0。在smarty2.0中,使用clear_all_cache删除所有可以,但clear_cache删除指定缓存,貌似也不行,这是为什么?
...全文
1785 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
aoyunhuowa 2013-08-31
  • 打赏
  • 举报
回复
引用 3 楼 xuzuning 的回复:
clearCache() — 清除缓存 说明 void clearCache(string template, string cache_id, string compile_id, int expire_time); 模板中如果有使用多个缓存,则可以通过cache_id指定清除相关缓存。 你可以指定第三个参数 $compile_id, 在模板组中清除一组模板,详见 缓存 了解更多。 第四个参数提供了一个最小时间,在这时间到来之前,缓存将会被清除。 Example 14.11. clearCache()
<?php
// 清除特定模板的缓存
$smarty->clearCache('index.tpl');

// 清除多个缓存的模板中某个特定缓存id的缓存
$smarty->clearCache('index.tpl', 'MY_CACHE_ID');
?>
我的代码就是这样的呀,但执行后根本就不起作用,删除不了。
aoyunhuowa 2013-06-09
  • 打赏
  • 举报
回复
function clear_smarty_cache() { $derive_dir = 'D:/xxx/xxx/derive'; //编译文件、缓存存放根目录 $smarty = new Smarty(); //实例化smarty $smarty->cache_dir = $derive_dir . '/cache/'; //缓存存放目录 $result = $smarty->clearCache('newslist.html','newslist'); return $result; }
一起混吧 2013-06-09
  • 打赏
  • 举报
回复
建议把代码贴出来以供分析
xuzuning 2013-06-09
  • 打赏
  • 举报
回复
clearCache() — 清除缓存 说明 void clearCache(string template, string cache_id, string compile_id, int expire_time); 模板中如果有使用多个缓存,则可以通过cache_id指定清除相关缓存。 你可以指定第三个参数 $compile_id, 在模板组中清除一组模板,详见 缓存 了解更多。 第四个参数提供了一个最小时间,在这时间到来之前,缓存将会被清除。 Example 14.11. clearCache()
<?php
// 清除特定模板的缓存
$smarty->clearCache('index.tpl');

// 清除多个缓存的模板中某个特定缓存id的缓存
$smarty->clearCache('index.tpl', 'MY_CACHE_ID');
?>

4,250

社区成员

发帖
与我相关
我的任务
社区描述
国内外优秀PHP框架讨论学习
社区管理员
  • Framework
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧