在会话中存储的购物车 [英] Storing shopping cart in session

查看:84
本文介绍了在会话中存储的购物车的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道了如购物车中的商品信息,普遍的共识是将它们存储在会话中。但有关属于可以被其他用户更改用户对象是什么?说,例如,易趣一样的网站。如果您存储在会话的用户的项目,其中包含当前的出价金额,而另一个用户进来,放在了该项目的投标,你就必须在会议上同时更新数据库的项目以及该项目,不是吗?

I know the general consensus for information like shopping cart items is to store them in session. But what about objects that belong to a user that can be altered by other users? Say, for instance, an eBay-like site. If you store a user's "items" in session, which contain the current bid amount, and another user comes in and places a bid on that item, you would have to update both the item in the database as well as the item in session, wouldn't you?

在这样的情况下,在会话存储和刷新每当另一个用户采取任何行动影响一个人的会话值或存储在数据库中的一切,每一次检索它(可以得到昂贵的,如果,比方说,你唯一的选择显示每一页的侧面板)的投标。

In cases like these, are the only options to store in session and refresh whenever any action another user takes affects a person's session values or store everything in the database and retrieve it every time (could get expensive if, say, you have the bids displayed on the side panel of every page).

推荐答案

我想这一切存储在数据库中,每次检索。根据数据缓存的波动几秒钟可能是为了。最大的问题是保持两者是一致的。

I would store it all in the database and retrieve it everytime. Depending on the volatility of the data caching for a few seconds may be in order. The biggest problem is keeping the two consistent.

我想你想的到,每次检索数据是不贵。数据库是非常有效的,如果你是基于一个关键的仰视。我宁可简单的侧(店DB和检索),直到性能问题负载(即负载测试)下显示。

I think that it isn't as expensive as you think to retrieve the data every time. Databases are very efficient if you are looking up based on a key. I'd err on the side of simplicity (store in DB and retrieve) until performance problems show up under load (ie in Load Testing).

如果有只打算是次寥寥,您可以使用应用程序缓存(除非你有一个以上的工作进程/服务器),并确保数据库和缓存保持同步。

If there is only going to be a handful of times, you may be able to use the Application Cache (unless you have more than one worker process/server) and make sure the DB and cache stay in sync.

这篇关于在会话中存储的购物车的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆