Skip to content

Commit 1fdfd36

Browse files
[13.x] Add Cache::touch() docs (#10849)
* feat: add Cache::touch() docs * modify: add tag * Update cache.md * Update cache.md --------- Co-authored-by: Taylor Otwell <[email protected]>
1 parent 8570457 commit 1fdfd36

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

cache.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
- [Obtaining a Cache Instance](#obtaining-a-cache-instance)
88
- [Retrieving Items From the Cache](#retrieving-items-from-the-cache)
99
- [Storing Items in the Cache](#storing-items-in-the-cache)
10+
- [Extending Item Lifetime](#extending-item-lifetime)
1011
- [Removing Items From the Cache](#removing-items-from-the-cache)
1112
- [The Cache Helper](#the-cache-helper)
1213
- [Atomic Locks](#atomic-locks)
@@ -287,6 +288,21 @@ The `add` method will only add the item to the cache if it does not already exis
287288
Cache::add('key', 'value', $seconds);
288289
```
289290

291+
<a name="extending-item-lifetime"></a>
292+
### Extending Item Lifetime
293+
294+
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`:
295+
296+
```php
297+
Cache::touch('key', 3600);
298+
```
299+
300+
You may provide a `DateTimeInterface`, `DateInterval`, or `Carbon` instance to specify an exact expiration time:
301+
302+
```php
303+
Cache::touch('key', now()->addHours(2));
304+
```
305+
290306
<a name="storing-items-forever"></a>
291307
#### Storing Items Forever
292308

0 commit comments

Comments
 (0)