Add Cache::touch()
& Store::touch()
for TTL Extension
#55954
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.
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()
returntrue
on success andfalse
when the item is not found in the cache.Cache:touch()
accepts anint
,DateTimeInterface
, orDateInterval
for extending the TTL;null
will extend the TTL indefinitely;$store->touch()
requires anint
(conversion is handled in theRepository
.This pull request includes the following:
Cache
FacadeRepository
andStore
ContractsApcStore
,ArrayStore
,DatabaseStore
,DynamoDbStore
,FileStore
,MemcachedStore
,MemoizedStore
,NullStore
, andRedisStore
Primary 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
+SET
operations, uses singleEXPIRE
commandSELECT
+UPDATE
, uses singleUPDATE
on timestampTOUCH
command instead ofGET
+SET
Memory Efficiency
Cache::touch($key, $seconds)
is immediately understandabletouch()
command developers know