Skip to content

Commit 407c91a

Browse files
committed
wip
1 parent 3c06bff commit 407c91a

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

session.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
- [Flash Data](#flash-data)
1010
- [Deleting Data](#deleting-data)
1111
- [Regenerating the Session ID](#regenerating-the-session-id)
12+
- [Session Cache](#session-cache)
1213
- [Session Blocking](#session-blocking)
1314
- [Adding Custom Session Drivers](#adding-custom-session-drivers)
1415
- [Implementing the Driver](#implementing-the-driver)
@@ -277,6 +278,25 @@ If you need to regenerate the session ID and remove all data from the session in
277278
$request->session()->invalidate();
278279
```
279280

281+
<a name="session-cache"></a>
282+
## Session Cache
283+
284+
Laravel's session cache provides a convenient way to cache data that is scoped to an individual user session. Unlike the global application cache, session cache data is automatically isolated per session and is cleaned up when the session expires or is destroyed. The session cache supports all the familiar [Laravel cache methods](/docs/{{version}}/cache) like `get`, `put`, `remember`, `forget`, and more, but scoped to the current session.
285+
286+
The session cache is perfect for storing temporary, user-specific data that you want to persist across multiple requests within the same session, but don't need to store permanently. This includes things like form data, temporary calculations, API responses, or any other ephemeral data that should be tied to a specific user's session.
287+
288+
You can access the session cache through the `cache` method on the session:
289+
290+
```php
291+
$discount = $request->session()->cache()->get('discount');
292+
293+
$request->session()->cache()->put(
294+
'discount', 10, now()->addMinutes(5)
295+
);
296+
```
297+
298+
For more information on Laravel's cache methods, consult the [cache documentation](/docs/{{version}}/cache).
299+
280300
<a name="session-blocking"></a>
281301
## Session Blocking
282302

0 commit comments

Comments
 (0)