Storage capabilities describes how a storage adapter works and which features it supports.
To get capabilities of a storage adapter, you can use the method getCapabilities() of the storage adapter but only the storage adapter and its plugins have permissions to change them.
Because capabilities are mutable, for example, by changing some options, you can subscribe to the “change” event to get notifications; see the examples for details.
If you are writing your own plugin or adapter, you can also change capabilities because you have access to the marker object and can create your own marker to instantiate a new object of Zend\Cache\Storage\Capabilities.
Constructor
Get supported datatypes.
Return type: | array |
---|
Set supported datatypes.
Return type: | Zend\Cache\Storage\Capabilities |
---|
Get supported metadata.
Return type: | array |
---|
Set supported metadata.
Return type: | Zend\Cache\Storage\Capabilities |
---|
Get minimum supported time-to-live.
(Returning 0 means items never expire)
Return type: | integer |
---|
Set minimum supported time-to-live.
Return type: | Zend\Cache\Storage\Capabilities |
---|
Get maximum supported time-to-live.
Return type: | integer |
---|
Set maximum supported time-to-live.
Return type: | Zend\Cache\Storage\Capabilities |
---|
Is the time-to-live handled static (on write), or dynamic (on read).
Return type: | boolean |
---|
Set if the time-to-live is handled statically (on write) or dynamically (on read).
Return type: | Zend\Cache\Storage\Capabilities |
---|
Get time-to-live precision.
Return type: | float |
---|
Set time-to-live precision.
Return type: | Zend\Cache\Storage\Capabilities |
---|
Get the “use request time” flag status.
Return type: | boolean |
---|
Set the “use request time” flag.
Return type: | Zend\Cache\Storage\Capabilities |
---|
Get flag indicating if expired items are readable.
Return type: | boolean |
---|
Set if expired items are readable.
Return type: | Zend\Cache\Storage\Capabilities |
---|
Get maximum key length.
Return type: | integer |
---|
Set maximum key length.
Return type: | Zend\Cache\Storage\Capabilities |
---|
Get if namespace support is implemented as a key prefix.
Return type: | boolean |
---|
Set if namespace support is implemented as a key prefix.
Return type: | Zend\Cache\Storage\Capabilities |
---|
Get namespace separator if namespace is implemented as a key prefix.
Return type: | string |
---|
Set the namespace separator if namespace is implemented as a key prefix.
Return type: | Zend\Cache\Storage\Capabilities |
---|
Get storage capabilities and do specific stuff in base of it
1 2 3 4 5 6 7 8 9 10 11 | use Zend\Cache\StorageFactory;
$cache = StorageFactory::adapterFactory('filesystem');
$supportedDatatypes = $cache->getCapabilities()->getSupportedDatatypes();
// now you can run specific stuff in base of supported feature
if ($supportedDatatypes['object']) {
$cache->set($key, $object);
} else {
$cache->set($key, serialize($object));
}
|
Listen to change event
1 2 3 4 5 6 7 8 9 10 11 12 13 | use Zend\Cache\StorageFactory;
$cache = StorageFactory::adapterFactory('filesystem', array(
'no_atime' => false,
));
// Catching capability changes
$cache->getEventManager()->attach('capability', function($event) {
echo count($event->getParams()) . ' capabilities changed';
});
// change option which changes capabilities
$cache->getOptions()->setNoATime(true);
|
The source code of this file is hosted on GitHub. Everyone can update and fix errors in this document with few clicks - no downloads needed.