Passed
Push — master ( f445f9...f90742 )
by Jean-Christophe
01:43
created

ArrayApcCache::getApcKey()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Ubiquity\cache\system;
4
5
/**
6
 * This class is responsible for storing Arrays in PHP files, and require php APCu.
7
 */
8
class ArrayApcCache extends ArrayCache {
9
10
	/**
11
	 * {@inheritDoc}
12
	 * @see \Ubiquity\cache\system\ArrayCache::storeContent()
13
	 */
14
	protected function storeContent($key, $content, $tag) {
15
		parent::storeContent($key, $content, $tag);
16
		$apcK=$this->getApcKey($key);
17
		if (apcu_exists($apcK)){
18
			apcu_delete($apcK);
19
		}
20
	}
21
	
22
	protected function apcDelete($key){
23
		$apcK=$this->getApcKey($key);
24
		if (apcu_exists($apcK)){
25
			return apcu_delete($apcK);
26
		}
27
		return false;
28
	}
29
	
30
	protected function getApcKey($key){
31
		return md5($this->_root.$key);
32
	}
33
34
	/**
35
	 * {@inheritDoc}
36
	 * @see \Ubiquity\cache\system\ArrayCache::fetch()
37
	 */
38
	public function fetch($key) {
39
		$apcK=$this->getApcKey($key);
40
		if (apcu_exists($apcK)){
41
			return apcu_fetch($apcK);
42
		}
43
		$content= parent::fetch($key);
44
		apcu_store($apcK, $content);
45
		return $content;
46
	}
47
48
49
	/**
50
	 *
51
	 * {@inheritdoc}
52
	 * @see \Ubiquity\cache\system\AbstractDataCache::remove()
53
	 */
54
	public function remove($key) {
55
		$this->apcDelete($key);
56
		return parent::remove($key);
57
	}
58
59
60
}
61