Zend\Cache\Storage\Capabilities¶
Overview¶
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.
Available Methods¶
- __construct
__construct(stdClass $marker, array $capabilities = array ( ), null|Zend\Cache\Storage\Capabilities $baseCapabilities)
Returns void
- hasEventManager
hasEventManager()
Returns if the dependency of Zend\EventManager is available.
Returns boolean
- getEventManager
getEventManager()
Get the event manager
Returns Zend\EventManager\EventCollection instance.
- getSupportedDatatypes
getSupportedDatatypes()
Get supported datatypes.
Returns array.
- setSupportedDatatypes
setSupportedDatatypes(stdClass $marker, array $datatypes)
Set supported datatypes.
Implements a fluent interface.
- getSupportedMetadata
getSupportedMetadata()
Get supported metadata.
Returns array.
- setSupportedMetadata
setSupportedMetadata(stdClass $marker, string $metadata)
Set supported metadata
Implements a fluent interface.
- getMaxTtl
getMaxTtl()
Get maximum supported time-to-live
Returns int
- setMaxTtl
setMaxTtl(stdClass $marker, int $maxTtl)
Set maximum supported time-to-live
Implements a fluent interface.
- getStaticTtl
getStaticTtl()
Is the time-to-live handled static (on write), or dynamic (on read).
Returns boolean
- setStaticTtl
setStaticTtl(stdClass $marker, boolean $flag)
Set if the time-to-live is handled statically (on write) or dynamically (on read)
Implements a fluent interface.
- getTtlPrecision
getTtlPrecision()
Get time-to-live precision.
Returns float.
- setTtlPrecision
setTtlPrecision(stdClass $marker, float $ttlPrecision)
Set time-to-live precision.
Implements a fluent interface.
- getUseRequestTime
getUseRequestTime()
Get the “use request time” flag status
Returns boolean
- setUseRequestTime
setUseRequestTime(stdClass $marker, boolean $flag)
Set the “use request time” flag.
Implements a fluent interface.
- getExpiredRead
getExpiredRead()
Get flag indicating if expired items are readable.
Returns boolean
- setExpiredRead
setExpiredRead(stdClass $marker, boolean $flag)
Set if expired items are readable.
Implements a fluent interface.
- getMaxKeyLength
getMaxKeyLength()
Get maximum key lenth.
Returns int
- setMaxKeyLength
setMaxKeyLength(stdClass $marker, int $maxKeyLength)
Set maximum key lenth.
Implements a fluent interface.
- getNamespaceIsPrefix
getNamespaceIsPrefix()
Get if namespace support is implemented as a key prefix.
Returns boolean
- setNamespaceIsPrefix
setNamespaceIsPrefix(stdClass $marker, boolean $flag)
Set if namespace support is implemented as a key prefix.
Implements a fluent interface.
- getNamespaceSeparator
getNamespaceSeparator()
Get namespace separator if namespace is implemented as a key prefix.
Returns string
- setNamespaceSeparator
setNamespaceSeparator(stdClass $marker, string $separator)
Set the namespace separator if namespace is implemented as a key prefix.
Implements a fluent interface.
- getIterable
getIterable()
Get if items are iterable.
Returns boolean
- setIterable
setIterable(stdClass $marker, boolean $flag)
Set if items are iterable.
Implements a fluent interface.
- getClearAllNamespaces
getClearAllNamespaces()
Get flag indicating support to clear items of all namespaces.
Returns boolean
- setClearAllNamespaces
setClearAllNamespaces(stdClass $marker, boolean $flag)
Set flag indicating support to clear items of all namespaces.
Implements a fluent interface.
- getClearByNamespace
getClearByNamespace()
Get flag indicating support to clear items by namespace.
Returns boolean
- setClearByNamespace
setClearByNamespace(stdClass $marker, boolean $flag)
Set flag indicating support to clear items by namespace.
Implements a fluent interface.
Examples¶
Get storage capabilities and do specific stuff in base of it
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | use Zend\Cache\StorageFactory;
$cache = StorageFactory::adapterFactory('filesystem');
$capabilities = $cache->getCapabilities();
// now you can run specific stuff in base of supported feature
if ($capabilities->getIterable()) {
$cache->find();
while ( ($item => $cache->fetch()) ) {
echo $item['key'] . ': ' . $item['value'] . "\n";
}
} else {
echo 'Iterating cached items not supported.';
}
|
Listen to change event
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | use Zend\Cache\StorageFactory;
$cache = StorageFactory::adapterFactory('filesystem', array(
'no_atime' => false,
));
$capabilities = $cache->getCapabilities();
// Catching the change event
$capabilities->getEventManager()->attach('change', function() {
echo 'Capabilities changed';
});
// change option which changes capabilities
$cache->getOptions()->setNoATime(true);
/*
* Will output:
* "Capabilities changed"
*/
|