Test Failed
Push — master ( ccf43a...ee4cc3 )
by Jean-Christophe
17:42
created

AbstractDataCache::setRoot()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 1
c 0
b 0
f 0
dl 0
loc 2
ccs 0
cts 0
cp 0
rs 10
cc 1
nc 1
nop 1
crap 2
1
<?php
2
3
/**
4
 * Cache systems
5
 */
6
namespace Ubiquity\cache\system;
7
8
use Ubiquity\exceptions\CacheException;
9
10
/**
11
 * This class is responsible for storing Arrays in PHP files.
12
 * Inspired by (c) Rasmus Schultz <[email protected]>
13
 * <https://github.com/mindplay-dk/php-annotations>
14
 * Ubiquity\cache\system$AbstractDataCache
15
 * This class is part of Ubiquity
16
 *
17
 * @author jcheron <[email protected]>
18
 * @version 1.0.1
19
 *
20
 */
21
abstract class AbstractDataCache {
22
23
	protected $_root;
24
25
	protected $postfix;
26
27
	public function __construct($root, $postfix = "") {
28
		$this->setRoot($root);
29
		$this->postfix = $postfix;
30 111
	}
31 111
32 111
	public function init() {}
33 111
34
	/**
35
	 * Check if annotation-data for the key has been stored.
36
	 *
37
	 * @param string $key
38
	 *        	cache key
39
	 * @return string[]|boolean true if data with the given key has been stored; otherwise false
40
	 */
41
	abstract public function exists($key);
42
43
	public function expired($key, $duration) {
44
		if ($this->exists($key)) {
45
			if (\is_int($duration) && $duration !== 0) {
46
				return \time() - $this->getTimestamp($key) > $duration;
47
			} else {
48
				return false;
49
			}
50
		} else {
51
			return true;
52
		}
53
	}
54
55
	/**
56
	 * Caches the given data with the given key.
57
	 *
58
	 * @param string $key
59
	 *        	cache key
60
	 * @param string $code
61
	 *        	the source-code to be cached
62
	 * @param string $tag
63
	 *        	the item tag
64 33
	 * @throws CacheException
65 33
	 */
66 33
	abstract public function store($key, $code, $tag = null);
67 33
68 33
	public function getRoot() {
69 33
		return $this->_root;
70 33
	}
71
72
	/**
73
	 *
74
	 * @param mixed $_root
75
	 */
76
	public function setRoot($_root) {
77
		$this->_root = $_root;
78
	}
79
80
	/**
81
	 * Fetches data stored for the given key.
82
	 *
83
	 * @param string $key
84
	 *        	cache key
85
	 * @return mixed the cached data
86
	 */
87
	abstract public function fetch($key);
88
89
	/**
90
	 * return data stored for the given key.
91
	 *
92
	 * @param string $key
93
	 *        	cache key
94
	 * @return mixed the cached data
95
	 */
96
	abstract public function file_get_contents($key);
97
98
	/**
99
	 * Returns the timestamp of the last cache update for the given key.
100
	 *
101
	 * @param string $key
102
	 *        	cache key
103
	 * @return boolean|int unix timestamp
104
	 */
105
	abstract public function getTimestamp($key);
106
107
	/**
108
	 *
109
	 * @param string $key
110
	 */
111
	abstract public function remove($key);
112
113
	/**
114
	 * Clears all cache entries
115
	 */
116
	abstract public function clear();
117
118
	abstract public function getCacheFiles($type);
119
120
	abstract public function clearCache($type);
121
122
	public function getCacheInfo() {
123
		return "Cache system is an instance of <b>" . \get_class($this) . "</b>.";
124
	}
125 3
126 3
	abstract public function getEntryKey($key);
127
}
128