From 3eb653675676e46b94c9b13809989b56129b2229 Mon Sep 17 00:00:00 2001 From: Ali Khosrojerdi Date: Wed, 8 Oct 2025 18:02:33 +0330 Subject: [PATCH 1/4] feat: add Cache::touch() docs --- cache.md | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/cache.md b/cache.md index b5a9d2a455f..e299d94c97f 100644 --- a/cache.md +++ b/cache.md @@ -287,6 +287,31 @@ The `add` method will only add the item to the cache if it does not already exis Cache::add('key', 'value', $seconds); ``` + +#### Extending Cache Lifetime + +The `touch` method allows you to extend the lifetime (TTL) of an existing cache item without retrieving or re-storing its value. +This is particularly useful when you need to keep frequently accessed data, such as active sessions or popular content, fresh without introducing unnecessary read/write overhead. + +The method will return `true` if the cache item exists and its expiration time was successfully extended. +If the item does not exist in the cache, the method will return `false`. + +```php +Cache::touch('user_session:123', 3600); +``` + +You may also pass a DateTimeInterface, DateInterval, or Carbon instance to specify an exact expiration time: + +```php +Cache::touch('user_session', now()->addHours(2)); +``` + +Passing null as the second argument will extend the cache item indefinitely (no expiration): + +```php +Cache::touch('user_session', null); +``` + #### Storing Items Forever From ca7109eb62559aba8d519da277703a7bbd01042b Mon Sep 17 00:00:00 2001 From: Ali Khosrojerdi Date: Wed, 8 Oct 2025 18:30:48 +0330 Subject: [PATCH 2/4] modify: add tag --- cache.md | 1 + 1 file changed, 1 insertion(+) diff --git a/cache.md b/cache.md index e299d94c97f..f3366b8a306 100644 --- a/cache.md +++ b/cache.md @@ -7,6 +7,7 @@ - [Obtaining a Cache Instance](#obtaining-a-cache-instance) - [Retrieving Items From the Cache](#retrieving-items-from-the-cache) - [Storing Items in the Cache](#storing-items-in-the-cache) + - [Extending Cache Lifetime](#extending-cache-lifetime) - [Removing Items From the Cache](#removing-items-from-the-cache) - [The Cache Helper](#the-cache-helper) - [Atomic Locks](#atomic-locks) From c6bcc83638929065fd62afea3dacfaf7a37b0599 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Wed, 8 Oct 2025 16:07:03 -0500 Subject: [PATCH 3/4] Update cache.md --- cache.md | 24 +++++++----------------- 1 file changed, 7 insertions(+), 17 deletions(-) diff --git a/cache.md b/cache.md index f3366b8a306..08644df8f47 100644 --- a/cache.md +++ b/cache.md @@ -7,7 +7,7 @@ - [Obtaining a Cache Instance](#obtaining-a-cache-instance) - [Retrieving Items From the Cache](#retrieving-items-from-the-cache) - [Storing Items in the Cache](#storing-items-in-the-cache) - - [Extending Cache Lifetime](#extending-cache-lifetime) + - [Extending Item Lifetime](#extending-item-lifetime) - [Removing Items From the Cache](#removing-items-from-the-cache) - [The Cache Helper](#the-cache-helper) - [Atomic Locks](#atomic-locks) @@ -288,29 +288,19 @@ The `add` method will only add the item to the cache if it does not already exis Cache::add('key', 'value', $seconds); ``` - -#### Extending Cache Lifetime + +### Extending Item Lifetime -The `touch` method allows you to extend the lifetime (TTL) of an existing cache item without retrieving or re-storing its value. -This is particularly useful when you need to keep frequently accessed data, such as active sessions or popular content, fresh without introducing unnecessary read/write overhead. - -The method will return `true` if the cache item exists and its expiration time was successfully extended. -If the item does not exist in the cache, the method will return `false`. - -```php -Cache::touch('user_session:123', 3600); -``` - -You may also pass a DateTimeInterface, DateInterval, or Carbon instance to specify an exact expiration time: +The `touch` method allows you to extend the lifetime (TTL) of an existing cache item without retrieving or re-storing its value. The `touch` method will return `true` if the cache item exists and its expiration time was successfully extended. If the item does not exist in the cache, the method will return `false`: ```php -Cache::touch('user_session', now()->addHours(2)); +Cache::touch('key', 3600); ``` -Passing null as the second argument will extend the cache item indefinitely (no expiration): +You may provide a `DateTimeInterface`, `DateInterval`, or `Carbon` instance to specify an exact expiration time: ```php -Cache::touch('user_session', null); +Cache::touch('key', now()->addHours(2)); ``` From 70e2d2c7ae40386aa9d0410aa74137d6685cf9de Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Wed, 8 Oct 2025 16:07:27 -0500 Subject: [PATCH 4/4] Update cache.md --- cache.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cache.md b/cache.md index 08644df8f47..ddd657a57da 100644 --- a/cache.md +++ b/cache.md @@ -291,7 +291,7 @@ Cache::add('key', 'value', $seconds); ### Extending Item Lifetime -The `touch` method allows you to extend the lifetime (TTL) of an existing cache item without retrieving or re-storing its value. The `touch` method will return `true` if the cache item exists and its expiration time was successfully extended. If the item does not exist in the cache, the method will return `false`: +The `touch` method allows you to extend the lifetime (TTL) of an existing cache item. The `touch` method will return `true` if the cache item exists and its expiration time was successfully extended. If the item does not exist in the cache, the method will return `false`: ```php Cache::touch('key', 3600);