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-cachev3 - 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
supportedMetadatacapability (useMetadataCapableInterface#getMetadatainstead) - Verify that you are not using
KeyListIteratorwith modeCURRENT_AS_METADATA(use the returnedkeyinstead and pass it to theMetadataCapablestorage adapter (NOTE: not all adapters do implementMetadataCapableInterface) - If you use the
Serializerplugin - Verify that if you pass a
stringasserializeroption, you do not directly depend on the return value ofPluginOptions#getSerializer(method will returnstringinstead of instantiating a newSerializerInterfaceinstance). The plugin itself can still handlestringand an instance ofSerializerInterfaceas 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
ObjectCachepattern, that your code does not expect an instance ofCallbackCacheto be passed
New Features
- Every adapter which supports
metadatanow implementsMetadataCapableInterfaceand provides a dedicated object containing all the metadata values it supports - Adds support for
psr/cacheandpsr/simple-cachev2 & v3
Removed Classes
Laminas\Cache\Exception\MissingKeyException
Breaking Changes
AbstractAdapterandStorageInterfaceare not aware of the methodsgetMetadataanymore. These were moved to the newMetadataCapableInterfaceCapabilitiesdo not providesupportedMetadataanymore. 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 anywayKeyListIteratorand the correspondingIteratorInterfacedoes not provide themodeCURRENT_AS_METADATAanymorePluginOptions#getSerializerdoes not create a serializer anymore if astringoption was passed, instead, thestringis returned- Increment and decrement feature was removed from
StorageInterface, so there is no moreStorageInterface#incrementItem,StorageInterface#decrementItem,StorageInterface#decrementItemsandStorageInterface#incrementItems- this also removes
incrementItem,incrementItems,decrementItem,derementItemsevents (pre,postandexception)
- this also removes
- Every method now has native return types
- Every property now has native types
- Every method argument now has native types
ObjectCachedoes not inherit theCallbackCachepattern anymore