|
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.2 |
|
12
|
|
|
* |
|
13
|
|
|
*/ |
|
14
|
|
|
class ArrayApcCache extends ArrayCache { |
|
15
|
|
|
|
|
16
|
|
|
public function storeContent($key, $content, $tag = null) { |
|
17
|
|
|
parent::store ( $key, $content, $tag ); |
|
18
|
|
|
$apcK = $this->getApcKey ( $key ); |
|
19
|
|
|
if ($this->apcExists ( $apcK )) { |
|
20
|
|
|
\apc_delete ( $apcK ); |
|
21
|
|
|
} |
|
22
|
|
|
} |
|
23
|
|
|
|
|
24
|
|
|
public function apcExists($key) { |
|
25
|
|
|
$success = false; |
|
26
|
|
|
\apc_fetch ( $key, $success ); |
|
27
|
|
|
return $success; |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
protected function apcDelete($key) { |
|
31
|
|
|
$apcK = $this->getApcKey ( $key ); |
|
32
|
|
|
if ($this->apcExists ( $apcK )) { |
|
33
|
|
|
return \apc_delete ( $apcK ); |
|
34
|
|
|
} |
|
35
|
|
|
return false; |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
protected function getApcKey($key) { |
|
39
|
|
|
return md5 ( $this->_root . $key ); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* |
|
44
|
|
|
* {@inheritdoc} |
|
45
|
|
|
* @see \Ubiquity\cache\system\ArrayCache::fetch() |
|
46
|
|
|
*/ |
|
47
|
|
|
public function fetch($key) { |
|
48
|
|
|
$apcK = $this->getApcKey ( $key ); |
|
49
|
|
|
if ($this->apcExists ( $apcK )) { |
|
50
|
|
|
return \apc_fetch ( $apcK ); |
|
51
|
|
|
} |
|
52
|
|
|
$content = parent::fetch ( $key ); |
|
53
|
|
|
\apc_store ( $apcK, $content ); |
|
54
|
|
|
return $content; |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* |
|
59
|
|
|
* {@inheritdoc} |
|
60
|
|
|
* @see \Ubiquity\cache\system\AbstractDataCache::remove() |
|
61
|
|
|
*/ |
|
62
|
|
|
public function remove($key) { |
|
63
|
|
|
$this->apcDelete ( $key ); |
|
64
|
|
|
return parent::remove ( $key ); |
|
65
|
|
|
} |
|
66
|
|
|
} |
|
67
|
|
|
|