GAE,数据库更新前的memcache [英] GAE, memcache before DB update

查看:68
本文介绍了GAE,数据库更新前的memcache的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在memcache和GAE DB操作方面遇到了一些麻烦。
如果我在数据库操作之后更新memcache rigth,x.put(),例如,我的memcache函数经常返回旧值。如果我使用睡眠(),缓存更正常,但这是不正确的,在我看来

  sleep(0.2)
data = Picture.all()。order(' - created')。fetch(300)
memcache.set('pictures_all',data)
pre>

我需要做什么才能获得正确的内存缓存?

解答:
需要使用父母查询,所有图片实体必须有相同的父母,那么你会得到强有力的结果

  data = picture.all()。order(' -  created')。ancestor(main_key())。fetch(300)
memcache.set('pictures_all',data)


  data.put()
memcache.set(key,data)


I have some troubles with memcache and GAE DB operations. if i update memcache rigth after DB operations, x.put(), for example, my memcache function often return old value. If i use sleep(), cache more often correct, but this is not right, in my opinion

sleep(0.2) 
data = Picture.all().order('-created').fetch(300)
memcache.set('pictures_all', data)

What i need to do, to get correct memcache?

ANSWER: Need to use parent with query, all Picture entities must have same parent, then you get strong consistant results

data = Picture.all().order('-created').ancestor(main_key()).fetch(300)
memcache.set('pictures_all', data)

解决方案

If you have the data, just update one entry in the memcache, no need to retrieve all from memcache. Something like

data.put()
memcache.set(key, data)

这篇关于GAE,数据库更新前的memcache的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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