Passed
Push — master ( b707db...f445f9 )
by Jean-Christophe
01:46
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
		if (apcu_exists($this->_root.$key)){
17
			apcu_delete($this->_root.$key);
18
		}
19
	}
20
	
21
	protected function apcDelete($key){
22
		if (apcu_exists($this->_root.$key)){
23
			return apcu_delete($this->_root.$key);
24
		}
25
		return false;
26
	}
27
28
	/**
29
	 * {@inheritDoc}
30
	 * @see \Ubiquity\cache\system\ArrayCache::fetch()
31
	 */
32
	public function fetch($key) {
33
		if (apcu_exists($this->_root.$key)){
34
			return apcu_fetch($this->_root.$key);
35
		}
36
		$content= parent::fetch($key);
37
		apcu_store($this->_root.$key, $content);
38
		return $content;
39
	}
40
41
42
	/**
43
	 *
44
	 * {@inheritdoc}
45
	 * @see \Ubiquity\cache\system\AbstractDataCache::remove()
46
	 */
47
	public function remove($key) {
48
		$this->apcDelete($key);
49
		return parent::remove($key);
50
	}
51
52
53
}
54