3 * Zend Framework (http://framework.zend.com/)
5 * @link http://github.com/zendframework/zf2 for the canonical source repository
6 * @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com)
7 * @license http://framework.zend.com/license/new-bsd New BSD License
10 namespace Zend\Cache\Storage\Adapter
;
13 use Zend\Cache\Storage\AvailableSpaceCapableInterface
;
14 use Zend\Cache\Storage\Capabilities
;
15 use Zend\Cache\Storage\ClearByNamespaceInterface
;
16 use Zend\Cache\Storage\ClearByPrefixInterface
;
17 use Zend\Cache\Storage\ClearExpiredInterface
;
18 use Zend\Cache\Storage\FlushableInterface
;
19 use Zend\Cache\Storage\IterableInterface
;
20 use Zend\Cache\Storage\OptimizableInterface
;
21 use Zend\Cache\Storage\StorageInterface
;
22 use Zend\Cache\Storage\TaggableInterface
;
23 use Zend\Cache\Storage\TotalSpaceCapableInterface
;
25 class BlackHole
implements
27 AvailableSpaceCapableInterface
,
28 ClearByNamespaceInterface
,
29 ClearByPrefixInterface
,
30 ClearExpiredInterface
,
35 TotalSpaceCapableInterface
38 * Capabilities of this adapter
40 * @var null|Capabilities
42 protected $capabilities = null;
45 * Marker to change capabilities
49 protected $capabilityMarker;
54 * @var null|AdapterOptions
61 * @param null|array|\Traversable|AdapterOptions $options
63 public function __construct($options = null)
66 $this->setOptions($options);
73 * @param array|\Traversable|AdapterOptions $options
74 * @return BlackHole Provides a fluent interface
76 public function setOptions($options)
78 if ($this->options
!== $options) {
79 if (! $options instanceof AdapterOptions
) {
80 $options = new AdapterOptions($options);
84 $this->options
->setAdapter(null);
86 $options->setAdapter($this);
87 $this->options
= $options;
95 * @return AdapterOptions
97 public function getOptions()
99 if (! $this->options
) {
100 $this->setOptions(new AdapterOptions());
102 return $this->options
;
109 * @param bool $success
110 * @param mixed $casToken
111 * @return mixed Data on success, null on failure
113 public function getItem($key, & $success = null, & $casToken = null)
120 * Get multiple items.
123 * @return array Associative array of keys and values
125 public function getItems(array $keys)
131 * Test if an item exists.
136 public function hasItem($key)
142 * Test multiple items.
145 * @return array Array of found keys
147 public function hasItems(array $keys)
153 * Get metadata of an item.
156 * @return array|bool Metadata on success, false on failure
158 public function getMetadata($key)
164 * Get multiple metadata
167 * @return array Associative array of keys and metadata
169 public function getMetadatas(array $keys)
178 * @param mixed $value
181 public function setItem($key, $value)
187 * Store multiple items.
189 * @param array $keyValuePairs
190 * @return array Array of not stored keys
192 public function setItems(array $keyValuePairs)
194 return array_keys($keyValuePairs);
201 * @param mixed $value
204 public function addItem($key, $value)
210 * Add multiple items.
212 * @param array $keyValuePairs
213 * @return array Array of not stored keys
215 public function addItems(array $keyValuePairs)
217 return array_keys($keyValuePairs);
221 * Replace an existing item.
224 * @param mixed $value
227 public function replaceItem($key, $value)
233 * Replace multiple existing items.
235 * @param array $keyValuePairs
236 * @return array Array of not stored keys
238 public function replaceItems(array $keyValuePairs)
240 return array_keys($keyValuePairs);
244 * Set an item only if token matches
246 * It uses the token received from getItem() to check if the item has
247 * changed before overwriting it.
249 * @param mixed $token
251 * @param mixed $value
254 public function checkAndSetItem($token, $key, $value)
260 * Reset lifetime of an item
265 public function touchItem($key)
271 * Reset lifetime of multiple items.
274 * @return array Array of not updated keys
276 public function touchItems(array $keys)
287 public function removeItem($key)
293 * Remove multiple items.
296 * @return array Array of not removed keys
298 public function removeItems(array $keys)
308 * @return int|bool The new value on success, false on failure
310 public function incrementItem($key, $value)
316 * Increment multiple items.
318 * @param array $keyValuePairs
319 * @return array Associative array of keys and new values
321 public function incrementItems(array $keyValuePairs)
331 * @return int|bool The new value on success, false on failure
333 public function decrementItem($key, $value)
339 * Decrement multiple items.
341 * @param array $keyValuePairs
342 * @return array Associative array of keys and new values
344 public function decrementItems(array $keyValuePairs)
350 * Capabilities of this storage
352 * @return Capabilities
354 public function getCapabilities()
356 if ($this->capabilities
=== null) {
357 // use default capabilities only
358 $this->capabilityMarker
= new stdClass();
359 $this->capabilities
= new Capabilities($this, $this->capabilityMarker
);
361 return $this->capabilities
;
364 /* AvailableSpaceCapableInterface */
367 * Get available space in bytes
371 public function getAvailableSpace()
376 /* ClearByNamespaceInterface */
379 * Remove items of given namespace
381 * @param string $namespace
384 public function clearByNamespace($namespace)
389 /* ClearByPrefixInterface */
392 * Remove items matching given prefix
394 * @param string $prefix
397 public function clearByPrefix($prefix)
402 /* ClearExpiredInterface */
405 * Remove expired items
409 public function clearExpired()
414 /* FlushableInterface */
417 * Flush the whole storage
421 public function flush()
426 /* IterableInterface */
429 * Get the storage iterator
431 * @return KeyListIterator
433 public function getIterator()
435 return new KeyListIterator($this, []);
438 /* OptimizableInterface */
441 * Optimize the storage
445 public function optimize()
450 /* TaggableInterface */
453 * Set tags to an item by given key.
454 * An empty array will remove all tags.
457 * @param string[] $tags
460 public function setTags($key, array $tags)
466 * Get tags of an item by given key
469 * @return string[]|FALSE
471 public function getTags($key)
477 * Remove items matching given tags.
479 * If $disjunction only one of the given tags must match
480 * else all given tags must match.
482 * @param string[] $tags
483 * @param bool $disjunction
486 public function clearByTags(array $tags, $disjunction = false)
491 /* TotalSpaceCapableInterface */
494 * Get total space in bytes
498 public function getTotalSpace()