[13.x] Cache::touch() & Store::touch() for TTL Extension#55954
[13.x] Cache::touch() & Store::touch() for TTL Extension#55954taylorotwell merged 8 commits intolaravel:masterfrom
Cache::touch() & Store::touch() for TTL Extension#55954Conversation
|
Thanks for submitting a PR! Note that draft PR's are not reviewed. If you would like a review, please mark your pull request as ready for review in the GitHub user interface. Pull requests that are abandoned in draft may be closed due to inactivity. |
52bc6b1 to
73fa810
Compare
Cache::touch() & Store::touch() for TTL Extension
|
This is pretty cool. One caveat though is the addition of the method to the cache repository contract which will be a breaking change to any existing implementations. For that reason we may probably need to target this to |
Cache::touch() & Store::touch() for TTL ExtensionCache::touch() & Store::touch() for TTL Extension
73fa810 to
485efd0
Compare
|
@taylorotwell Done. |
| /** | ||
| * Set the expiration of a cached item; null TTL will retain indefinitely. | ||
| */ | ||
| public function touch(string $key, DateTimeInterface|DateInterval|int|null $ttl = null): bool; |
There was a problem hiding this comment.
Adding a method to a public interface is a major breaking change.
There was a problem hiding this comment.
this is targetting master now, should be fine.
There was a problem hiding this comment.
In theory, I could drop the notation from the Cache facade and the method from the Repository interface, but would still need to do something like method_exists and return false or throw an exception that the driver doesn't support touch() if we dropped it from the Store interface. That would allow it to target 12.x, but not sure that's necessarily better than targeting master.
I'm open to whatever y'all think, of course.
| /** | ||
| * Set the expiration of a cached item. | ||
| */ | ||
| public function touch(string $key, int $ttl): bool; |
There was a problem hiding this comment.
Adding a method to a public interface is a major breaking change.
There was a problem hiding this comment.
this is targetting master now, should be fine.
There was a problem hiding this comment.
It can be removed from the Store interface, but that would require doing something like method_exists and return false or throw an exception that the driver doesn't support the feature in Repository::touch(). That would allow it to target 12.x, but not sure that's necessarily better than targeting master.
I'm open to whatever y'all think, of course.
Cache::touch() & Store::touch() for TTL ExtensionCache::touch() & Store::touch() for TTL Extension
Cache::touch() & Store::touch() for TTL ExtensionCache::touch() & Store::touch() for TTL Extension
|
@yitzwillroth This is a very nice addition, am all for it. One thing i noticed is that no code have been changed to the tags repositories? Does this new cache method work out of the box with cache tags? |
|
Thanks! |
|
The whole point of this was to avoid the get. Yet the get is used at least once and sometimes twice... |
This pull request introduces the
Cache::touch()method, addressing a fundamental challenge that developers encounter frequently: extending cache TTL without the overhead of retrieving and re-storing data.Basic Usage:
Simplifies Common Patterns:
Cache:touch()&$store->touch()returntrueon success andfalsewhen the item is not found in the cache.Cache:touch()accepts anint,DateTimeInterface, orDateIntervalfor extending the TTL;nullwill extend the TTL indefinitely;$store->touch()requires anint(conversion is handled in theRepository.This pull request includes the following:
CacheFacadeRepositoryandStoreContractsApcStore,ArrayStore,DatabaseStore,DynamoDbStore,FileStore,MemcachedStore,MemoizedStore,NullStore, andRedisStorePrimary Use Cases
1. Activity-Based Cache Extension
2. Cache Warming Maintenance
3. Progressive Cache Strategies
Real-World Scenarios
E-commerce Product Caching
API Response Caching
Performance Benefits
Network/Storage Efficiency
GET+SEToperations, uses singleEXPIREcommandSELECT+UPDATE, uses singleUPDATEon timestampTOUCHcommand instead ofGET+SETMemory Efficiency
Cache::touch($key, $seconds)is immediately understandabletouch()command developers know💁🏼♂️ The author is available for hire -- inquire at [email protected].