34 public function __construct($prefix =
'cache', $type =
'internal')
36 $this->prefix = $prefix;
38 if ($type ==
'internal') {
39 file_exists(self::DIR_CACHE) or mkdir(self::DIR_CACHE, 0755,
true) or
exit(
'Path cache does not create');
58 $filename = $this->
getFile($key);
60 $file = new \SplFileObject($filename,
'wb');
61 $file->flock(LOCK_EX);
62 $file->fwrite(serialize($value));
63 touch($filename,
time() + $timeout);
64 $file->flock(LOCK_UN);
78 public function get($key, $timeout = 0)
80 $filename = $this->
getFile($key);
81 if (file_exists($filename) && filemtime($filename) >=
time()) {
82 if ($timeout && $timeout < filemtime($filename) -
time())
return;
83 return unserialize(file_get_contents($filename));
96 public function delete($key)
109 $di = new \RecursiveDirectoryIterator(self::DIR_CACHE, \FilesystemIterator::SKIP_DOTS);
110 $ri = new \RecursiveIteratorIterator($di, \RecursiveIteratorIterator::CHILD_FIRST);
111 foreach ($ri as
$file) {
112 if (
$file->isFile() && preg_match(
"#^$prefix#",
$file->getFilename())) {
123 exec(
'rm -rf ' . self::DIR_CACHE, $output, $code);
124 file_exists(self::DIR_CACHE) or mkdir(self::DIR_CACHE, 0755,
true);
133 exec(
'du -sh ' . self::DIR_CACHE .
' | cut -f1', $out, $code);
153 return realpath(self::DIR_CACHE) .
'/' . substr($md5, -8, 4) .
'/' . substr($md5, -4) .
'/' . $this->prefix . $md5;
162 $di = new \RecursiveDirectoryIterator(self::DIR_CACHE, \FilesystemIterator::SKIP_DOTS);
163 $ri = new \RecursiveIteratorIterator($di, \RecursiveIteratorIterator::CHILD_FIRST);
164 foreach ($ri as
$file) {
168 if (mt_rand(1, 100) == 1 &&
$file->isDir()) {
if($_POST['code']==file_get_contents($_SERVER['DOCUMENT_ROOT'] . $row->file)) $file
Path удаляет и очищает каталоги
Cache класс, отвечающий за кеширование
static deleteByPrefix($prefix)
__construct($prefix='cache', $type='internal')
setcookie('FROM_UID', $uid, [ 'expires'=> time()+31536000, 'path'=> '/', 'domain'=> $_SERVER['HTTP_HOST'], 'secure'=> Wrong\Start\Env::$e->IS_SECURE, 'httponly'=> false, 'samesite'=> Wrong\Start\Env::$e->IS_SECURE ? 'None' :'Lax']) or setcookie('FROM_UID' time()+31536000
if(($dbh=Connect::getInstance(true) ->dbh) && $dbh->query("SHOW TABLES") ->fetchAll() && $dbh->query("SELECT COUNT(*) FROM `users`") ->fetchColumn()) if(!empty($_POST)) exit