Several storage mechanisms such as Cookie and session

Source: Internet
Author: User

In the early days of the Internet, because HTTP is stateless, the so-called stateless means that different requests and operations are independent of each other, and there is no relationship between them, HTTP does not store any request information for you. Although it can be achieved by hiding the domain, it is very troublesome, and it is only limited to the same web page. Netscape, a pioneer in the Internet, has added a simple and useful feature of HTTP-cookies ).

So what is Cookie? When the client sends a request to the server, the server processes the information sent from the client, and a cookie is generated. This is where the server will have two segments of information, some of the information is sent from the client, and some are processed by the server. The cookie will save some of the information. Then return to the client through the header and save it on the client PC machine. This is the generation of cookies.

When we talk about cookies, we will inevitably think of sessions. Sessions and cookies have the same purpose, but they are different in different scenarios. They have their own advantages and disadvantages.
Session stores the customer's information in the memory. The storage format is like a dictionary table, which has a sessionid, And the sessionid will exist on the client like a cookie. If the customer logs in to the next time, HTTP matches the sessionid with the sessionid in the server memory to determine whether the user exists. Sessions is safer than Cookie because it has memory, because cookie stores customer information on the client. However, if you want to store a large amount of user information, it will greatly increase the pressure on the server, which may cause the server to crash and the consequences will be unimaginable. Although the cookie is a little less secure, it reduces the pressure on the server. In other words, most people will not use cookies to steal other users' users or passwords. Therefore, 90% of websites are currently using Cookie technology.
Some people think that I want to make the customer's information relatively secure, and I want to use Session, which is actually implemented. Because the session not only exists in the memory, it can also exist in the database, and you can store as much space as you have left on the hard disk. The cookie is saved for 30 minutes by default. You can customize the cookie as needed. The cookie can be saved for up to 50 years.
Of course, besides cookies and session state sessions, there are some other state management functions that can be achieved by applications and cache, but both of them are global. For example, the cache is best used to store relatively stable data for a certain period of time. It is generally public information, because it will overwrite the data. Therefore, if you need to log on to the cache, I feel that they are not necessary.

I have summarized the above information for cainiao's reference and I will not guarantee it.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.