views:

239

answers:

3

Where should I store shopping cart data in session or in database? (I think in amazon.com shopping cart after user logout and after month login again his orders that he choose in shopping cart saved) Thanks, Yosef

+1  A: 

If your shopping cart software can make the most of abandoned carts (send reminders that maybe they should come back and finsh the sale ect) and flush them from database and does good database housecleaning then keep them in the database.

If it only allows a return user to continue with current cart items then keep them hashed in cookie.

If you want a fresh cart on a return visit then maybe leave in session.

RandyMorris
Thanks,for answers!I would like to know how shopping cart design in meduam-big ecommerce website done in terms of Session and database.
Yosef
+1  A: 

How about both? When you read shopping cart data, check your session first. If it's there, you save a trip to the database (if your session isn't backed by a database). When you write, write to session and persist to the database. That way, you get speedy reads and the user doesn't lose their cart when they close their browser.

Corbin March
A: 

I often update cart data into database first and keep a cached version for read-only requests e.g. showing a mini-cart on every page. Cart data should be read optimized. And because of cart data is often small so I'd like to keep it for anonymous users for months, store it in cookies too.

Tiendq