如何清除TP的文件缓存

jerry thinkphp 2015年11月18日 收藏
很多时候,当我们在操作过程中,调整了表结构或者需要因为特殊的原因手动清理掉某些缓存文件时,需要用到这个方法。仅限于File缓存的方式。
很多时候,当我们在操作过程中,调整了表结构或者需要因为特殊的原因手动清理掉某些缓存文件时,需要用到这个方法。仅限于File缓存的方式。

如果要删除其他的缓存也是可以的,你可以去找一下TP的系统变量,里面有其他几个缓存目录的常量。

使用方法,直接用调用cache_clear方法即可。写的比较简单,如果需要请自行扩充,另外,很多教程里说,要用到IO类来删除缓存,可惜的是TP的3.1版本之后都没看到这个类在那里。或许是我没找到。
  1. public function cache_clear() {
  2.         $this->deldir(TEMP_PATH);
  3.     }

  4.     function deldir($dir) {
  5.         $dh = opendir($dir);
  6.         while ($file = readdir($dh)) {
  7.             if ($file != "." && $file != "..") {
  8.                 $fullpath = $dir . "/" . $file;
  9.                 if (!is_dir($fullpath)) {
  10.                     unlink($fullpath);
  11.                 } else {
  12.                     deldir($fullpath);
  13.                 }
  14.             }
  15.         }
  16.     }