7 const EXPIRE
= 3600; // 1h
8 const CLEAN_EXPIRE
= 86400; // 1 day
10 protected static function _getCacheDir()
12 return DATA_ROOT
. '/cache/static';
15 protected static function _getCachePath($id)
17 $id = 'cache_' . sha1($id);
18 return self
::_getCacheDir() . '/' . $id;
21 static public function store($id, $content)
23 $path = self
::_getCachePath($id);
24 return (bool) file_put_contents($path, $content);
27 static public function expired($id, $expire = self
::EXPIRE
)
29 $path = self
::_getCachePath($id);
30 $time = @filemtime
($path);
37 return ($time > (time() - (int)$expire)) ?
false : true;
40 static public function get($id)
42 $path = self
::_getCachePath($id);
43 return file_get_contents($path);
46 static public function display($id)
48 $path = self
::_getCachePath($id);
49 return readfile($path);
52 static public function getPath($id)
54 return self
::_getCachePath($id);
57 static public function remove($id)
59 $path = self
::_getCachePath($id);
63 static public function clean($expire = self
::CLEAN_EXPIRE
)
65 $dir = self
::_getCacheDir();
68 $expire = time() - $expire;
70 while ($file = $d->read())
77 if (filemtime($dir . '/' . $file) > $expire)
79 unlink($dir . '/' . $file);