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