aierong [original work]
It is the first time to create a shopping cart for a BToC site. I summarized the storage method of data in the shopping cart.
Method 1: Use session
Any type of data can be stored in the session. Each user has a unique session ID. This ID is used to distinguish the shopping cart session data of different users. The session data is stored in the memory of the WEB server. If there are many users using the shopping cart, then First, it will occupy a large amount of server resources. The session has a small flaw. It relies on COOKIE to communicate with the user. Once the user closes the COOKIE, using the session will be more troublesome.
Of course, in ASP. There are two other ways to save session data in NET. One is to designate another server to store the session data, which can effectively share the operating overhead of the WEB server.
The other is to store the session data in MS SQL. MS SQL is implemented using local temporary tables. The session data is placed in the local temporary tables. MS SQL also assigns a unique ID to each local temporary table
. I think it is Use this ID to distinguish different session data of different users. However, I do not recommend this method. Frequently creating and deleting temporary tables in the database will cause too much overhead to the database.
Method 2: Use a table (ShoppingCart) in the database.
My favorite implementation method is
that the table has several basic fields.
CartId shopping cart ID (unique)
Id Product ID (unique)
The quantity of goods purchased by Qty users
CreateDate Shopping cart creation time
The field CartId of this table is the ID of the shopping cart that distinguishes different users. If the user is logged in, you can store the ID of the login name of the logged in user in the table. If the user is not logged in and uses the shopping cart,
you can give It assigns a GUID (Globally Unique Identifier) as the shopping cart ID.
This method also has some flaws. First, it will cause a large amount of invalid data. As we all know, people who use the shopping cart may not eventually check out and purchase goods. But to use the shopping cart
, you have to insert relevant data into the table (ShoppingCart). As soon as a non-logged in user leaves the site, his data in the table becomes a pile of waste data, because when he logs in next time, we allocate to
him A new CartId shopping cart ID. If there is waste data, we have to maintain this table from time to time. We can write a process to clear the waste data (using the fields CreateDate and CartId to determine invalid data). You can also call it manually. If you want to do it by If MS SQL is run on our behalf, a JOB can be set up, and the JOB will automatically call the process to clear the waste data.
Talking about the shortcomings of pulling, we should talk about the advantages of this method.
1. It takes up less system resources. We can place the database in one computer and the WEB server in another computer, so that system resources can be fully utilized.
2. The data in the shopping cart can be effectively retained. We can imagine that a customer suddenly leaves the shopping station for some other reason (crash, etc.) while shopping. His data in the shopping cart is effectively
retained
. When he logs in next time, the shopping cart will be saved.There is also the data retained last time to prevent users from purchasing goods again (this function is only valid for logged-in users' shopping carts). If a session is used to implement
the shopping cart, once all users leave the site, all the data in their shopping carts will be lost. The failure
is easy, I just summarized these, because I just came into contact with ASP. NET, I don’t know much about many aspects. There may be other ways to implement a shopping cart. I hope you can give me some advice. Thank you all.