Provides various official and user-released code examples. For code reference, you are welcome to exchange and learn that the default File Cache cannot be cleaned up in batches by prefix. Let's share it with Xiaojia, we hope the next version can be integrated. S ('%', null, array ('key' => true, 'prefix' => 'pre _');
./ThinkPHP/Library/Think/Cache/Driver/File. class. php
/**
* Clear the Directory
* @ Param string $ dir directory path
* @ Param boolean $ stay whether to retain the Directory
* @ Param string $ pattern file filtering rule
* @ Return boolean
*/
Protected function clearDir ($ dir, $ stay = true, $ pattern = null ){
If (is_dir ($ dir )){
$ Dir = rtrim ($ dir, '\\/'). DIRECTORY_SEPARATOR;
$ List = array_merge (glob ($ dir. '*', GLOB_ONLYDIR), glob ($ dir. "{$ pattern} *. *", GLOB_NOSORT ));
Foreach ($ list as $ file ){
$ This-> clearDir ($ file ,! Is_null ($ pattern), $ pattern );
}
$ Stay | rmdir ($ dir );
} Elseif (is_file ($ dir )){
Return unlink ($ dir );
}
Return true;
}Usage:
S('%', null, array('key' => true, 'prefix' =>'pre_');
AD: truly free, domain name + VM + enterprise mailbox = 0 RMB