1 | <?php |
||
12 | abstract class AbstractStorage { |
||
13 | |||
14 | /** |
||
15 | * Cached field names |
||
16 | * |
||
17 | * @var array |
||
18 | */ |
||
19 | protected $fields = array(); |
||
20 | |||
21 | /** |
||
22 | * Number of hits |
||
23 | * @var int |
||
24 | */ |
||
25 | protected $hits = 0; |
||
26 | |||
27 | /** |
||
28 | * Number of misses |
||
29 | * @var int |
||
30 | */ |
||
31 | protected $misses = 0; |
||
32 | |||
33 | /** |
||
34 | * Cache provider Object |
||
35 | * @var object |
||
36 | */ |
||
37 | protected $provider; |
||
38 | |||
39 | /** |
||
40 | * Info method |
||
41 | * @var string |
||
42 | */ |
||
43 | protected $infoMethod = 'info'; |
||
44 | |||
45 | /** |
||
46 | * Key prefix to avoid collisions |
||
47 | * @var string |
||
48 | */ |
||
49 | protected $prefix = ''; |
||
50 | |||
51 | /** |
||
52 | * Retrieves the content of $name cache |
||
53 | * |
||
54 | * @SuppressWarnings(PHPMD.UnusedFormalParameter) |
||
55 | * @param string $name cache name |
||
56 | * |
||
57 | * @return mixed |
||
58 | */ |
||
59 | public function get($name, $compressed = false) { |
||
60 | $value = $this->provider->get($this->prefix . $name); |
||
61 | if ($value !== false) { |
||
62 | $this->hit(); |
||
63 | $this->storeName($name); |
||
64 | } else { |
||
65 | $this->miss(); |
||
66 | } |
||
67 | |||
68 | return $value; |
||
69 | } |
||
70 | |||
71 | /** |
||
72 | * Cache miss occured |
||
73 | */ |
||
74 | public function miss() { |
||
77 | |||
78 | /** |
||
79 | * Cache hit occured |
||
80 | */ |
||
81 | public function hit() { |
||
84 | |||
85 | /** |
||
86 | * Deletes the specified cache or each one if '' given |
||
87 | * |
||
88 | * @param string $name cache name |
||
89 | * |
||
90 | * @return bool |
||
91 | */ |
||
92 | public function delete($name = '') { |
||
93 | if ($name == '') { |
||
94 | return $this->provider->flush(); |
||
95 | } else { |
||
96 | return $this->provider->delete($this->prefix . $name); |
||
97 | } |
||
98 | } |
||
99 | |||
100 | /** |
||
101 | * Retrieves information of Cache state |
||
102 | * |
||
103 | * @param bool $getFields |
||
104 | * |
||
105 | * @return array |
||
106 | */ |
||
107 | public function info($getFields = false) { |
||
124 | |||
125 | /** |
||
126 | * Retrieves cache hits |
||
127 | * |
||
128 | * @return int |
||
129 | */ |
||
130 | public function getHits() { |
||
133 | |||
134 | /** |
||
135 | * Retrieves cache misses |
||
136 | * |
||
137 | * @return int |
||
138 | */ |
||
139 | public function getMisses() { |
||
142 | |||
143 | /** |
||
144 | * Stores cache name |
||
145 | * |
||
146 | * @param string $name |
||
147 | */ |
||
148 | protected function storeName($name) { |
||
153 | |||
154 | } |
||
155 |