On this page
Migration Guide
Migration to Version 4.0
Finally, native types everywhere. With v4.0, laminas-cache
depends on laminas-servicemanager
v4 which already introduced full native types and thus, cache now has native types as well.
Along with these changes, we also decided to remove and/or enhance some features to make the usage of this component more user-friendly.
So instead of working with metadata arrays, a new MetadataCapableInterface
was introduced which provides a generic interface for storage adapters to tell both IDEs and static analysers to understand what metadata instances are returned for which storage adapter.
This allows per-storage Metadata which can differ depending on the storage being used.
Checklist
- Ensure you are on latest
laminas/laminas-cache
v3 - Ensure you are on latest
laminas/laminas-cache-storage-adapter-*
version (might differ) - Verify that you are not using one of the following methods
StorageInterface#incrementItem
(no replacement available, should be implemented in userland code)StorageInterface#incrementItems
(no replacement available, should be implemented in userland code)StorageInterface#decrementItem
(no replacement available, should be implemented in userland code)StorageInterface#decrementItems
(no replacement available, should be implemented in userland code)- Verify that you are not using
supportedMetadata
capability (useMetadataCapableInterface#getMetadata
instead) - Verify that you are not using
KeyListIterator
with modeCURRENT_AS_METADATA
(use the returnedkey
instead and pass it to theMetadataCapable
storage adapter (NOTE: not all adapters do implementMetadataCapableInterface
) - If you use the
Serializer
plugin - Verify that if you pass a
string
asserializer
option, you do not directly depend on the return value ofPluginOptions#getSerializer
(method will returnstring
instead of instantiating a newSerializerInterface
instance). The plugin itself can still handlestring
and an instance ofSerializerInterface
as in previous versions - If you provide own plugins, storage adapters, pattern, you have to upgrade to v4 and update all method/argument/property (return-) types according to the updated versions. Check out rector which can help with this kind of migration
- If you are handling
Laminas\Cache\Exception\MissingKeyException
, you can remove that code as the exception does not exist anymore - Check if you use
ObjectCache
pattern, that your code does not expect an instance ofCallbackCache
to be passed
New Features
- Every adapter which supports
metadata
now implementsMetadataCapableInterface
and provides a dedicated object containing all the metadata values it supports - Adds support for
psr/cache
andpsr/simple-cache
v2 & v3
Removed Classes
Laminas\Cache\Exception\MissingKeyException
Breaking Changes
AbstractAdapter
andStorageInterface
are not aware of the methodsgetMetadata
anymore. These were moved to the newMetadataCapableInterface
Capabilities
do not providesupportedMetadata
anymore. The supported metadata is tied to the used storage adapter and thus, was already requiring projects to explicitly know the exact implementation of the cache backend in case of using these metadatas anywayKeyListIterator
and the correspondingIteratorInterface
does not provide themode
CURRENT_AS_METADATA
anymorePluginOptions#getSerializer
does not create a serializer anymore if astring
option was passed, instead, thestring
is returned- Increment and decrement feature was removed from
StorageInterface
, so there is no moreStorageInterface#incrementItem
,StorageInterface#decrementItem
,StorageInterface#decrementItems
andStorageInterface#incrementItems
- this also removes
incrementItem
,incrementItems
,decrementItem
,derementItems
events (pre
,post
andexception
) - Every method now has native return types
- Every property now has native types
- Every method argument now has native types
ObjectCache
does not inherit theCallbackCache
pattern anymore