|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Doctrine\Common\Cache; |
|
4
|
|
|
|
|
5
|
|
|
use BadMethodCallException; |
|
6
|
|
|
use const XC_TYPE_VAR; |
|
|
|
|
|
|
7
|
|
|
use function ini_get; |
|
8
|
|
|
use function serialize; |
|
9
|
|
|
use function unserialize; |
|
10
|
|
|
use function xcache_clear_cache; |
|
11
|
|
|
use function xcache_get; |
|
12
|
|
|
use function xcache_info; |
|
13
|
|
|
use function xcache_isset; |
|
14
|
|
|
use function xcache_set; |
|
15
|
|
|
use function xcache_unset; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* Xcache cache driver. |
|
19
|
|
|
* |
|
20
|
|
|
* @deprecated |
|
21
|
|
|
* |
|
22
|
|
|
* @link www.doctrine-project.org |
|
23
|
|
|
*/ |
|
24
|
|
|
class XcacheCache extends CacheProvider |
|
25
|
|
|
{ |
|
26
|
|
|
/** |
|
27
|
|
|
* {@inheritdoc} |
|
28
|
|
|
*/ |
|
29
|
|
|
protected function doFetch($id) |
|
30
|
|
|
{ |
|
31
|
|
|
return $this->doContains($id) ? unserialize(xcache_get($id)) : false; |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* {@inheritdoc} |
|
36
|
|
|
*/ |
|
37
|
|
|
protected function doContains($id) |
|
38
|
|
|
{ |
|
39
|
|
|
return xcache_isset($id); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* {@inheritdoc} |
|
44
|
|
|
*/ |
|
45
|
|
|
protected function doSave($id, $data, $lifeTime = 0) |
|
46
|
|
|
{ |
|
47
|
|
|
return xcache_set($id, serialize($data), (int) $lifeTime); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* {@inheritdoc} |
|
52
|
|
|
*/ |
|
53
|
|
|
protected function doDelete($id) |
|
54
|
|
|
{ |
|
55
|
|
|
return xcache_unset($id); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* {@inheritdoc} |
|
60
|
|
|
*/ |
|
61
|
|
|
protected function doFlush() |
|
62
|
|
|
{ |
|
63
|
|
|
$this->checkAuthorization(); |
|
64
|
|
|
|
|
65
|
|
|
xcache_clear_cache(XC_TYPE_VAR); |
|
|
|
|
|
|
66
|
|
|
|
|
67
|
|
|
return true; |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* Checks that xcache.admin.enable_auth is Off. |
|
72
|
|
|
* |
|
73
|
|
|
* @return void |
|
74
|
|
|
* |
|
75
|
|
|
* @throws BadMethodCallException When xcache.admin.enable_auth is On. |
|
76
|
|
|
*/ |
|
77
|
|
|
protected function checkAuthorization() |
|
78
|
|
|
{ |
|
79
|
|
|
if (ini_get('xcache.admin.enable_auth')) { |
|
80
|
|
|
throw new BadMethodCallException( |
|
81
|
|
|
'To use all features of \Doctrine\Common\Cache\XcacheCache, ' |
|
82
|
|
|
. 'you must set "xcache.admin.enable_auth" to "Off" in your php.ini.' |
|
83
|
|
|
); |
|
84
|
|
|
} |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
/** |
|
88
|
|
|
* {@inheritdoc} |
|
89
|
|
|
*/ |
|
90
|
|
|
protected function doGetStats() |
|
91
|
|
|
{ |
|
92
|
|
|
$this->checkAuthorization(); |
|
93
|
|
|
|
|
94
|
|
|
$info = xcache_info(XC_TYPE_VAR, 0); |
|
|
|
|
|
|
95
|
|
|
|
|
96
|
|
|
return [ |
|
97
|
|
|
Cache::STATS_HITS => $info['hits'], |
|
98
|
|
|
Cache::STATS_MISSES => $info['misses'], |
|
99
|
|
|
Cache::STATS_UPTIME => null, |
|
100
|
|
|
Cache::STATS_MEMORY_USAGE => $info['size'], |
|
101
|
|
|
Cache::STATS_MEMORY_AVAILABLE => $info['avail'], |
|
102
|
|
|
]; |
|
103
|
|
|
} |
|
104
|
|
|
} |
|
105
|
|
|
|