1 | <?php |
||
35 | class ConfigurableCacheAdapter implements CacheAdapterInterface |
||
36 | { |
||
37 | |||
38 | /** |
||
39 | * The cache adatper instance. |
||
40 | * |
||
41 | * @var \TechDivision\Import\Cache\CacheAdapterInterface |
||
42 | */ |
||
43 | protected $cacheAdapter; |
||
44 | |||
45 | /** |
||
46 | * The TTL used to cache items. |
||
47 | * |
||
48 | * @var integer |
||
49 | */ |
||
50 | protected $ime = -1; |
||
51 | |||
52 | /** |
||
53 | * The flag if the cache is anabled or not. |
||
54 | * |
||
55 | * @var boolean |
||
56 | */ |
||
57 | protected $enabled = true; |
||
58 | |||
59 | /** |
||
60 | * Initialize the cache handler with the passed cache and configuration instances. |
||
61 | * . |
||
62 | * @param \TechDivision\Import\Cache\CacheAdapterInterface $cacheAdapter The cache instance |
||
63 | * @param \TechDivision\Import\ConfigurationInterface $configuration The configuration instance |
||
64 | * @param string $type The cache type to use |
||
65 | */ |
||
66 | public function __construct( |
||
82 | |||
83 | /** |
||
84 | * Creates a unique cache key from the passed data. |
||
85 | * |
||
86 | * @param mixed $data The date to create the cache key from |
||
87 | * |
||
88 | * @return string The generated cache key |
||
89 | */ |
||
90 | public function cacheKey($data) |
||
94 | |||
95 | /** |
||
96 | * Inversion of the isCached() method. |
||
97 | * |
||
98 | * @param string $key The cache key to query for |
||
99 | * |
||
100 | * @return boolean TRUE if the value is not available, else FALSE |
||
101 | */ |
||
102 | public function notCached($key) |
||
106 | |||
107 | /** |
||
108 | * Add's a cache reference from one key to another. |
||
109 | * |
||
110 | * @param string $from The key to reference from |
||
111 | * @param string $to The key to reference to |
||
112 | * |
||
113 | * @return void |
||
114 | */ |
||
115 | public function addReference($from, $to) |
||
119 | |||
120 | /** |
||
121 | * Returns a new cache item for the passed key |
||
122 | * |
||
123 | * @param string $key The cache key to return the item for |
||
124 | * |
||
125 | * @return mixed The value for the passed key |
||
126 | */ |
||
127 | public function fromCache($key) |
||
131 | |||
132 | /** |
||
133 | * Flush the cache and remove the references. |
||
134 | * |
||
135 | * @return void |
||
136 | */ |
||
137 | public function flushCache() |
||
141 | |||
142 | /** |
||
143 | * Remove the item with the passed key and all its references from the cache. |
||
144 | * |
||
145 | * @param string $key The key of the cache item to Remove |
||
146 | * |
||
147 | * @return void |
||
148 | */ |
||
149 | public function removeCache($key) |
||
153 | |||
154 | /** |
||
155 | * Raises the value for the attribute with the passed key by one. |
||
156 | * |
||
157 | * @param mixed $key The key of the attribute to raise the value for |
||
158 | * @param mixed $counterName The name of the counter to raise |
||
159 | * |
||
160 | * @return integer The counter's new value |
||
161 | */ |
||
162 | public function raiseCounter($key, $counterName) |
||
166 | |||
167 | /** |
||
168 | * This method merges the passed attributes with an array that |
||
169 | * has already been added under the passed key. |
||
170 | * |
||
171 | * If no value will be found under the passed key, the attributes |
||
172 | * will simply be registered. |
||
173 | * |
||
174 | * @param mixed $key The key of the attributes that has to be merged with the passed ones |
||
175 | * @param array $attributes The attributes that has to be merged with the exising ones |
||
176 | * |
||
177 | * @return void |
||
178 | * @throws \Exception Is thrown, if the already registered value is no array |
||
179 | * @link http://php.net/array_replace_recursive |
||
180 | */ |
||
181 | public function mergeAttributesRecursive($key, array $attributes) |
||
185 | |||
186 | /** |
||
187 | * Query whether or not a cache value for the passed cache key is available. |
||
188 | * |
||
189 | * @param string $key The cache key to query for |
||
190 | * |
||
191 | * @return boolean TRUE if the a value is available, else FALSE |
||
192 | */ |
||
193 | public function isCached($key) |
||
204 | |||
205 | /** |
||
206 | * Add the passed item to the cache. |
||
207 | * |
||
208 | * @param string $key The cache key to use |
||
209 | * @param mixed $value The value that has to be cached |
||
210 | * @param array $references An array with references to add |
||
211 | * @param boolean $override Flag that allows to override an exising cache entry |
||
212 | * @param integer $time The TTL in seconds for the passed item |
||
213 | * |
||
214 | * @return void |
||
215 | */ |
||
216 | public function toCache($key, $value, array $references = array(), $override = false, $time = null) |
||
224 | } |
||
225 |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: