在继续之前等待数据存储更新 [英] Wait for datastore update before proceeding

查看:31
本文介绍了在继续之前等待数据存储更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个轻量级应用程序,我有很多情况是用户提交表单,表单数据被处理并推送到数据存储区,然后用户被重定向到一个页面,显示一些相同的数据.用户在数据存储更新之前到达页面的情况经常发生,因此他们会看到旧数据.有没有办法让应用程序在继续之前等待数据存储更新?明显的hacky 解决方案是调用sleep(1),但这显然不理想,并且比实际更新花费的时间更长.

解决方案

只要得到 key .put() 返回:

key = mything.put()

并将其传递到另一个页面(例如通过 urlsafe).另一个页面可以重建密钥然后

thething = key.get()

总是为您提供更新的数据——即,这个 (key.get()) 是一种从 GAE 数据存储中获得强一致性的简单方法!

I'm working on a lightweight app, and I have quite a few situations where the user submits a form, the form data is processed and pushed to the datastore, and then the user is redirected to a page that displays some of the same data. It's quite often the case that the user gets to the page before the datastore has been updated, so they see old data. Is there any way to have the app wait for the datastore to update before proceeding? The obvious hacky solution is calling sleep(1), but that's obviously not ideal and takes longer than the actual update.

解决方案

Just get the key the .put() returns:

key = mything.put()

and pass it on to the other page (e.g via urlsafe). The other page can rebuild the key and then

thething = key.get()

will always give you updated data -- i.e, this (key.get()) is one simple way to get strong consistency from the GAE datastore!

这篇关于在继续之前等待数据存储更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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