Upgrading
Upgrading to Version 4.0
The minimum required PHP version is 8.4. The {cache} tag requires Latte 3.1.
A part of the work can be done for you by DressCode with the
dresscode/upgrade-nette package: it rewrites renamed classes and constants and reports what it cannot rewrite. See Upgrading Nette.
The interfaces Nette\Caching\IStorage, Nette\Caching\IBulkReader and
Nette\Caching\Storages\IJournal have been removed; use Nette\Caching\Storage,
Nette\Caching\BulkReader and Nette\Caching\Storages\Journal. The service aliases
cacheStorage and nette.cacheJournal have been removed as well; use the services
cache.storage and cache.journal, or autowiring.
The uppercase constants such as Cache::EXPIRE or Cache::TAGS and the method
Cache::start() now trigger E_USER_DEPRECATED. Use Cache::Expire, Cache::Tags
and capture(). Passing a closure as the data to Cache::save() is deprecated, pass it as the generator of
load().
Dependencies can be written as the new object Nette\Caching\Dependencies, see Expiration and Invalidation. The array with Cache::* keys
still works, but an unknown key or a value of a wrong type now throws an exception. Typically, this concerns a priority written as
a string, such as '50', which has to be an integer.
The method Cache::clean() takes the conditions as named arguments, such as
$cache->clean(tags: ['article/10']); the array is validated the same way as the dependencies. Several things
behave differently:
clean()without any condition throws an exception. To remove expired items, callclean([])on the storage.allon a cache with a namespace removes only that namespace and those derived from it; previously, it cleared the whole storage. To clear everything, call it on a cache without a namespace, or call$storage->clean([Cache::All => true]).- Cleaning by
Cache::Namespacesalso removes the namespaces derived from the given ones byderive().
A storage throws Nette\NotSupportedException for a dependency or a condition it cannot honor, instead of silently
ignoring it. SQLiteStorage does not support priorities or dependencies on files, constants, callbacks and other
items; MemcachedStorage does not support cleaning by namespaces. See the overview of storages.
PsrCacheAdapter now validates keys as PSR-16 requires, so it rejects keys containing any of
{}()/\@:, such as user:1.
If you have written your own storage, remove the method lock(), which no longer exists, and declare the return
type mixed of the method read(). A storage that should let only one process generate a missing item
implements the interface Nette\Caching\LockingReader. A subclass of Cache that overrides
clean() must declare its new parameters.
Upgrading to Version 3.1
- the method
Nette\Caching\Cache::start()was renamed tocapture()
Upgrading to Version 2.4
- the class
Nette\Caching\Storages\FileJournalis no longer available
Upgrading to Version 2.3
- the ancient and deprecated ArrayAccess syntax
$val = $cache[$key]or$cache[$key] = $valtriggersE_USER_DEPRECATED; use$cache->load($key)and$cache->save($key, $val)instead