8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
const CLEAN_EXPIRE = 86400; // 1 day
protected static function _getCacheDir()
{
return CACHE_ROOT . '/static';
}
protected static function _getCachePath($id)
{
$id = 'cache_' . sha1($id);
return self::_getCacheDir() . '/' . $id;
}
static public function store($id, $content)
{
$path = self::_getCachePath($id);
return (bool) file_put_contents($path, $content);
}
static public function expired($id, $expire = self::EXPIRE)
{
$path = self::_getCachePath($id);
$time = @filemtime($path);
if (!$time)
|
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
const CLEAN_EXPIRE = 86400; // 1 day
protected static function _getCacheDir()
{
return CACHE_ROOT . '/static';
}
protected static function __getCachePath($id)
{
$id = 'cache_' . sha1($id);
return self::_getCacheDir() . '/' . $id;
}
static public function store($id, $content)
{
$path = self::_getCachePath($id);
return (bool) file_put_contents($path, $content);
}
static public function storeFromPointer($id, $pointer)
{
$path = self::_getCachePath($id);
$fp = fopen($path, 'wb');
$ok = stream_copy_to_stream($pointer, $fp);
fclose($fp);
return $ok;
}
static public function storeFromUpload($id, $uploaded_file)
{
$path = self::_getCachePath($id);
return (bool) move_uploaded_file($uploaded_file, $path);
}
static public function expired($id, $expire = self::EXPIRE)
{
$path = self::_getCachePath($id);
$time = @filemtime($path);
if (!$time)
|
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
return readfile($path);
}
static public function getPath($id)
{
return self::_getCachePath($id);
}
static public function remove($id)
{
$path = self::_getCachePath($id);
return unlink($path);
}
|
>
>
>
>
>
|
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
|
return readfile($path);
}
static public function getPath($id)
{
return self::_getCachePath($id);
}
static public function exists($id)
{
return file_exists(self::_getCachePath($id));
}
static public function remove($id)
{
$path = self::_getCachePath($id);
return unlink($path);
}
|