NDB查询获取()和ContextOptions [英] NDB query fetch() and ContextOptions

查看:78
本文介绍了NDB查询获取()和ContextOptions的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的其中一个查询中禁用上下文缓存。我认为我可以这样做:



pre $ MyModel.query(ancestor = user.key).fetch(100,options = ContextOptions(use_cache = False,use_memcache = False))

  MyModel.query(ancestor = user.key).fetch(100,config = ContextOptions(use_cache = False,use_memcache = False))

但它似乎不适用于我。所以我的问题是如何使用 fetch 禁用缓存和内存缓存?



PS:



对于get(),它完美地工作:

$ p $ MyModel.query(ancestor = user.key).get use_cache = False,use_memcache = False)

谢谢!

解决方案

仅支持get()的缓存。来自文档


查询不会在任何缓存中查找值。但是,如果高速缓存策略如此说明(但
永远不会存储到Memcache),则查询结果是
写回上下文高速缓存。


如果您遇到某些似乎被缓存的实体的问题,则可能需要更改上下文缓存策略:

  ctx.set_cache_policy(lambda key:False)

set_cache_policy的参数必须是函数如果密钥必须被缓存,则取一个参数(键)并返回布尔值。在这里它总是返回False,所以没有实体会被缓存。


I would like to disable context cache in only one of my queries. I thought I could do it like this:

MyModel.query(ancestor=user.key).fetch(100, options=ContextOptions(use_cache=False, use_memcache=False))

or

MyModel.query(ancestor=user.key).fetch(100, config=ContextOptions(use_cache=False, use_memcache=False))

But it does not seem to work for me. So my question is how do I disable cache and memcache for queries using fetch?

PS:

For get() it works perfectly:

MyModel.query(ancestor=user.key).get(use_cache=False, use_memcache=False)

Thanks!

解决方案

Caching is supported only for get()'s. From the docs:

Queries do not look up values in any cache. However, query results are written back to the in-context cache if the cache policy says so (but never to Memcache).

If you are experiencing problems with some entities, which seem to be cached, you probably have to change context cache policy:

ctx.set_cache_policy(lambda key: False)

Argument of set_cache_policy has to be function taking one param (key) and returning boolean if the key has to be cached. Here it always returns False, so no entity will be cached.

这篇关于NDB查询获取()和ContextOptions的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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