Wednesday, 12 April 2023

Differences using Session and Cache in Laravel

1. Session 

- user_unique_session_id: each user session is associated with a unique session ID that is stored as a cookie on the user's browser.
- session data can be store in file, redis, database in hard disk...(by driver)
- throught user_unique_session_id, server can get session data

- notes: can NOT be used to store data that is specific to an asynchronous operation: in a background job can NOT access session data, because cannot access the session ID that is stored on the client-side

2. Cache 

- save data by key: value

- cache data can be store in file, redis, database in hard disk...

- note: can be accessed by any part of your application, including background jobs and other asynchronous tasks.

Learn more

* how laravel generate unique session IDs

- Laravel use the Illuminate\Session\Store class, which provides a variety of methods for managing and manipulating session data.

- By default, Laravel generates a new session ID for each user session using a cryptographically secure random string generator. The specific method used to generate the session ID varies depending on the driver used for session storage, but typically involves generating a random string of sufficient length and complexity to prevent guessing or brute-force attacks.

- Once the session ID has been generated, it is stored in a cookie on the user's browser. The cookie typically has a short lifespan, usually 20-30 minutes by default, after which it expires and the user must re-authenticate to continue their session.

- It's worth noting that Laravel provides various configuration options for session management, including the ability to customize the session ID generation algorithm and the session cookie settings. This allows developers to fine-tune the session management behavior of their application to best fit their specific needs and requirements.

 

Thank you.

 

No comments:

Post a Comment

Golang Advanced Interview Q&A