[5.8] Fix PSR-16 TTL conformity #27217
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Resend (and a better implementation) for #27166
These changes to the Cache Repository interface and implementation will make our cache implementation compliant with the PSR-16 standard's TTL requirements. It contains some significant changes in how we handle and store cache values.
The main change that was done is that now a TTL with a value of NULL will be considerd an attempt to store the item forever. In addition to this, any value with a TTL equal or lower than zero will be considerd an attempt to remove the item from the cache. The
put
,putMany
andadd
methods were updated to reflect these changes.Before these changes a request like
Cache::put('foo', 'bar')
wouldn't do anything since a NULL TTL meant that the call was simply ignored. Now any request without a specified TTL will have the default TTL of NULL and thus the request is considered to attempting to store the item forever.For the
putMany
call a NULL TTL now means that every single item will be stored forever individually. As there isn't aputManyForever
equivalent on the Repository or the PSR interface, there was no way to tell a cache store to store the given items in one go.For the
add
call, the behavior to ignore the call when a zero or less TTL was given is kept but when a NULL TTL is now passed, it's correctly passed to theput
method. This will ignore a customadd
method on the cache store as any NULL TTL simply could be considered to re-store the item indefinitely.No changes were made to the cache stores themselves. Only the Repository was modified. This way, the cache stores keep their current behavior as they aren't implementations of the PSR Simple Cache interface.
All in all these changes will now make us conform with the PSR spec much better.
For reference: https://www.php-fig.org/psr/psr-16/
Fixes #27160
PS. As a proof of concept I was able to simplify a call in the Filesystem component.