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
views:
239answers:
3If 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.
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.
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.