默认的文件缓存不能按前缀批量清理,小加改造分享一下,希望下个版本能整合进去。S('%', null, array('key' => true, 'prefix' =>'pre_');
./ThinkPHP/Library/Think/Cache/Driver/File.class.php /**<br>
* 清空目录<br>
* @param string $dir 目录路径<br>
* @param boolean $stay 是否保留目录<br>
* @param string $pattern 文件筛选规则<br>
* @return boolean<br>
*/<br>
protected function clearDir($dir, $stay = true, $pattern = null) {<br>
if (is_dir($dir)) {<br>
$dir = rtrim($dir, '\\/') . DIRECTORY_SEPARATOR;<br>
$list = array_merge(glob($dir . '*', GLOB_ONLYDIR), glob($dir . "{$pattern}*.*", GLOB_NOSORT));<br>
foreach ($list as $file) {<br>
$this->clearDir($file, !is_null($pattern), $pattern);<br>
}<br>
$stay || rmdir($dir);<br>
} elseif (is_file($dir)) {<br>
return unlink($dir);<br>
}<br>
return true;<br>
}
使用方法:S('%', null, array('key' => true, 'prefix' =>'pre_');
AD:真正免费,域名+虚机+企业邮箱=0元