Home >php教程 >php手册 >文件缓存前缀清理

文件缓存前缀清理

WBOY
WBOYOriginal
2016-06-07 11:38:511770browse

默认的文件缓存不能按前缀批量清理,小加改造分享一下,希望下个版本能整合进去。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元

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn