Test Failed
Push — master ( 64ee6d...363fb0 )
by Jean-Christophe
13:47
created

ArrayApcCache::apcExists()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 3
c 1
b 0
f 0
dl 0
loc 4
ccs 0
cts 4
cp 0
rs 10
cc 1
nc 1
nop 1
crap 2
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