对于get方法,从memcache生成一个列表。
对于post方法,用户从memcache的列表中选择一个帖子并对其执行某些操作。 (我再次检索内存缓存列表。)如何确保为post发现的memcache列表与为get检索的内存缓存列表相同?
我担心的情况是另一位用户在post方法运行之前提交新帖子并更改内存缓存。
代码:
def get(self):
sells = memcache.get("SELLS")
if sells is None:
*do some stuff*
else:
logging.error("OFFERS IN MC")
sells.sort(key = lambda x:x.price)
count = 1
self.render("buy.html", sells = sells, count = count)
def post(self):
first_name = self.request.get('first_name')
num = int(self.request.get('num'))
if first_name and num:
sells = memcache.get("SELLS")
*do some stuff*
self.redirect('/contact?first_name=' + first_name + "&amount=" + amount + "&price=" + price)
else:
cart_error = "fill in all the boxes"
self.render("buy.html", cart_error = cart_error, sells = list(sells))
答案 0 :(得分:1)
您可以尝试使用属于客户端对象的gets
和cas
方法。
请参阅:GAE Memecache Reference
我并不完全清楚你的情况究竟是什么。你担心的流程应该是: 1)get请求中的用户可以看到选项列表 2)然后他在帖子中选择其中一个选项 如果是这种情况,只需使用gets和cas就不会这样做,因为您需要跨请求跟踪对象,因此您可以尝试在memcache中保存另一个跟踪列表上次更新时间的变量并发送该变量进入浏览器,因此当用户发布时,您使用当前在memcache中的值检查浏览器中的值。如果它们不同,您就知道发生了更新。
另一个但也有问题的案例可能是: 1)get请求中的用户查看列表 2)用户在帖子中选择其中一个选项 3)同时另一个用户选择相同的选项 有了它,你将拥有一个不错的小种族位置。在这种情况下,gets,cas模型工作得很好,因为它只会让你更新对象,如果其他人没有触摸它。
我的猜测是你真的想要处理这两种潜在的情况。种族条件是一个婊子,我能说什么。