1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Ubiquity\cache\system; |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* This class is responsible for storing Arrays in PHP files, and require php apc. |
7
|
|
|
* Ubiquity\cache\system$ArrayApcCache |
8
|
|
|
* This class is part of Ubiquity |
9
|
|
|
* |
10
|
|
|
* @author jcheron <[email protected]> |
11
|
|
|
* @version 1.0.1 |
12
|
|
|
* |
13
|
|
|
*/ |
14
|
|
|
class ArrayApcCache extends ArrayCache { |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* |
18
|
|
|
* {@inheritdoc} |
19
|
|
|
* @see \Ubiquity\cache\system\ArrayCache::storeContent() |
20
|
|
|
*/ |
21
|
|
|
protected function storeContent($key, $content, $tag) { |
22
|
|
|
parent::storeContent ( $key, $content, $tag ); |
23
|
|
|
$apcK = $this->getApcKey ( $key ); |
24
|
|
|
if ($this->apcExists ( $apcK )) { |
25
|
|
|
\apc_delete ( $apcK ); |
26
|
|
|
} |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
public function apcExists($key) { |
30
|
|
|
$success = false; |
31
|
|
|
\apc_fetch ( $key, $success ); |
32
|
|
|
return $success; |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
protected function apcDelete($key) { |
36
|
|
|
$apcK = $this->getApcKey ( $key ); |
37
|
|
|
if ($this->apcExists ( $apcK )) { |
38
|
|
|
return \apc_delete ( $apcK ); |
39
|
|
|
} |
40
|
|
|
return false; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
protected function getApcKey($key) { |
44
|
|
|
return md5 ( $this->_root . $key ); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* |
49
|
|
|
* {@inheritdoc} |
50
|
|
|
* @see \Ubiquity\cache\system\ArrayCache::fetch() |
51
|
|
|
*/ |
52
|
|
|
public function fetch($key) { |
53
|
|
|
$apcK = $this->getApcKey ( $key ); |
54
|
|
|
if ($this->apcExists ( $apcK )) { |
55
|
|
|
return \apc_fetch ( $apcK ); |
56
|
|
|
} |
57
|
|
|
$content = parent::fetch ( $key ); |
58
|
|
|
\apc_store ( $apcK, $content ); |
59
|
|
|
return $content; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* |
64
|
|
|
* {@inheritdoc} |
65
|
|
|
* @see \Ubiquity\cache\system\AbstractDataCache::remove() |
66
|
|
|
*/ |
67
|
|
|
public function remove($key) { |
68
|
|
|
$this->apcDelete ( $key ); |
69
|
|
|
return parent::remove ( $key ); |
70
|
|
|
} |
71
|
|
|
} |
72
|
|
|
|