Comparison of advantages and disadvantages of several ways to realize shopping cart

  • 2021-09-20 19:46:21
  • OfStack

At present, there are three kinds of shopping carts, which are stored in cookie or session, or combined with database storage

The first is stored in cookie

Advantages:

1. cookie is stored in the client, and takes up very few resources. One cookie can store 300 cookie, and each cookie is 4KB, which can not only meet the needs of shopping carts, but also reduce the pressure on the server.
2. cookie is built into the browser, so data will not be lost within the validity period defined by cookie.
Zone 3.2 cookie is not an executable file, so it will not bring viruses to users or attack their systems

Disadvantages:

1. The shopping cart developed based on cookie requires that the user's browser must support and set to enable cookie, otherwise the shopping cart will be invalid.
2. There is an argument that cookie violates the privacy of visitors, so some users will disable the functions of cookie on this computer.
3. If you change a machine to log in, you will lose the shopping cart information;

The second is session

Advantages:

1. session can be synchronized with the client and does not depend on the settings with the client.
2. Compared with cookie, session is the information stored on the server side, so it is safer;

Disadvantages:.

1. session will occupy server resources and increase the load of the server, especially when there are many concurrent users, it will generate a large number of session, which will affect the performance of the server.
2. Because the information stored in session is more sensitive and stored in the server in the form of files, there are also potential safety hazards;

The third is the way to combine databases

This mode is quite common at present.
It has one feature

Advantages:

1. Database and cookie are responsible for recording data and maintaining replies respectively, which can give full play to their respective advantages and improve the security and server performance;
2. No matter which machine you switch to, the shopping cart information is not lost;

Disadvantages:

1. Every shopping behavior, must be connected with the database, until the operation of the table is completed, the connection is released. When there are many concurrent users, it will affect the performance of the database, which puts forward higher requirements for the performance of the database;
2. Maintaining a reply using cookie requires client support.


Related articles: