3 Storage capabilities describe how a storage adapter works, and which features it
6 To get capabilities of a storage adapter, you can use the method
7 `getCapabilities()`, but only the storage adapter and its plugins have
8 permissions to change them.
10 Because capabilities are mutable, you can subscribe to the "change" event to get
11 notifications; see the examples for details.
13 If you are writing your own plugin or adapter, you can also change capabilities
14 because you have access to the marker object and can create your own marker to
15 instantiate a new instance of `Zend\Cache\Storage\Capabilities`.
20 namespace Zend\Cache\Storage;
24 use Zend\Cache\Exception;
25 use Zend\EventManager\EventsCapableInterface;
32 * @param StorageInterface $storage
33 * @param stdClass $marker
34 * @param array $capabilities
35 * @param null|Capabilities $baseCapabilities
37 public function __construct(
38 StorageInterface $storage,
40 array $capabilities = [],
41 Capabilities $baseCapabilities = null
45 * Get the storage adapter
47 * @return StorageInterface
49 public function getAdapter();
52 * Get supported datatypes
56 public function getSupportedDatatypes();
59 * Set supported datatypes
61 * @param stdClass $marker
62 * @param array $datatypes
63 * @throws Exception\InvalidArgumentException
64 * @return Capabilities Fluent interface
66 public function setSupportedDatatypes(stdClass $marker, array $datatypes);
69 * Get supported metadata
73 public function getSupportedMetadata();
76 * Set supported metadata
78 * @param stdClass $marker
79 * @param string[] $metadata
80 * @throws Exception\InvalidArgumentException
81 * @return Capabilities Fluent interface
83 public function setSupportedMetadata(stdClass $marker, array $metadata);
86 * Get minimum supported time-to-live
88 * @return int 0 means items never expire
90 public function getMinTtl();
93 * Set minimum supported time-to-live
95 * @param stdClass $marker
97 * @throws Exception\InvalidArgumentException
98 * @return Capabilities Fluent interface
100 public function setMinTtl(stdClass $marker, $minTtl);
103 * Get maximum supported time-to-live
105 * @return int 0 means infinite
107 public function getMaxTtl();
110 * Set maximum supported time-to-live
112 * @param stdClass $marker
114 * @throws Exception\InvalidArgumentException
115 * @return Capabilities Fluent interface
117 public function setMaxTtl(stdClass $marker, $maxTtl);
120 * Is the time-to-live handled static (on write)
121 * or dynamic (on read)
125 public function getStaticTtl();
128 * Set if the time-to-live handled static (on write) or dynamic (on read)
130 * @param stdClass $marker
132 * @return Capabilities Fluent interface
134 public function setStaticTtl(stdClass $marker, $flag);
137 * Get time-to-live precision
141 public function getTtlPrecision();
144 * Set time-to-live precision
146 * @param stdClass $marker
147 * @param float $ttlPrecision
148 * @throws Exception\InvalidArgumentException
149 * @return Capabilities Fluent interface
151 public function setTtlPrecision(stdClass $marker, $ttlPrecision);
154 * Get use request time
158 public function getUseRequestTime();
161 * Set use request time
163 * @param stdClass $marker
165 * @return Capabilities Fluent interface
167 public function setUseRequestTime(stdClass $marker, $flag);
170 * Get if expired items are readable
173 * @deprecated This capability has been deprecated and will be removed in the future.
174 * Please use getStaticTtl() instead
176 public function getExpiredRead();
179 * Set if expired items are readable
181 * @param stdClass $marker
183 * @return Capabilities Fluent interface
184 * @deprecated This capability has been deprecated and will be removed in the future.
185 * Please use setStaticTtl() instead
187 public function setExpiredRead(stdClass $marker, $flag);
190 * Get maximum key lenth
192 * @return int -1 means unknown, 0 means infinite
194 public function getMaxKeyLength();
197 * Set maximum key length
199 * @param stdClass $marker
200 * @param int $maxKeyLength
201 * @throws Exception\InvalidArgumentException
202 * @return Capabilities Fluent interface
204 public function setMaxKeyLength(stdClass $marker, $maxKeyLength);
207 * Get if namespace support is implemented as prefix
211 public function getNamespaceIsPrefix();
214 * Set if namespace support is implemented as prefix
216 * @param stdClass $marker
218 * @return Capabilities Fluent interface
220 public function setNamespaceIsPrefix(stdClass $marker, $flag);
223 * Get namespace separator if namespace is implemented as prefix
227 public function getNamespaceSeparator();
230 * Set the namespace separator if namespace is implemented as prefix
232 * @param stdClass $marker
233 * @param string $separator
234 * @return Capabilities Fluent interface
236 public function setNamespaceSeparator(stdClass $marker, $separator);
242 ### Get storage capabilities and do specific stuff based on them
245 use Zend\Cache\StorageFactory;
247 $cache = StorageFactory::adapterFactory('filesystem');
248 $supportedDatatypes = $cache->getCapabilities()->getSupportedDatatypes();
250 // now you can run specific stuff in base of supported feature
251 if ($supportedDatatypes['object']) {
252 $cache->set($key, $object);
254 $cache->set($key, serialize($object));
258 ### Listen to the change event
261 use Zend\Cache\StorageFactory;
263 $cache = StorageFactory::adapterFactory('filesystem', [
267 // Catching capability changes
268 $cache->getEventManager()->attach('capability', function($event) {
269 echo count($event->getParams()) . ' capabilities changed';
272 // change option which changes capabilities
273 $cache->getOptions()->setNoATime(true);