Cache VS Session VS cookies?

前端 未结 8 754
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-02 04:09

What are the do\'s and don\'ts about Cache VS Session VS Cookies?

For example:
I\'m using Session variables a lot and sometimes have problems in a booking-applic

8条回答
  •  遥遥无期
    2020-12-02 04:36

    First thing you must know! cookies are used by session! The server knows who is your user thanks to the cookie which is exchanged between the client and server every request (this works with HTTP headers set-cookie and cookie).

    The real question is:

    • If you want to store user information during the navigation, then you should use session.

    • If your client doesn't support cookies, then you can decide to store a cookie inside each request, encoded in the URL (the server will use the URL instead of the cookie to find the right session for the request).

    Then consider where you want to store your session:
    If your site must have high disponibility and high performance, then you must not store session inside the process but inside a database. This way you will be able to share the work among several web server. But you will loose in simplicity (because objects you store in your session must be serializable), and you have one more round trip between your webserver and your database server.

提交回复
热议问题