使用投影查询时的 NDB 缓存 [英] NDB Caching When Using Projected Queries

查看:21
本文介绍了使用投影查询时的 NDB 缓存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

找不到之前问过的这个具体问题.在使用投影查询与完整实体查询时,App Engine 的 NDB 如何处理缓存?

Could not find this specific question asked before yet. How does App Engine's NDB handle caching when using projected queries vs. full entity queries?

例如,如果我先进行投影查询..

For example, if I do a projected query first..

MyModel.query().get(projected=['name'])

...然后接下来做一个常规查询...

...and then do a regular query next...

MyModel.query().get()

...我会得到什么?完整的实体?如果是这样,NDB 是否自动缓存了第一个查询的任何部分?或者 NDB 是否能够很好地区分,所以下次我运行投影查询时,它可能会从缓存中提取?

...what will I get? The full entity? If so, was ANY part of first query automatically cached by NDB? Or is NDB able to make the distinction well, so the next time I run the projected query it is potentially pulled from cache?

推荐答案

据我所知,查询结果仅缓存在上下文缓存中,但不会从缓存中获取查询结果.

As far as I'm aware, query results are only cached in in-context cache, but results are not fetched from cache for queries.

key.get() 将被缓存并从缓存中检索,但 query.get() 不会从缓存中检索.

key.get() will be cached and retrieved from cache, but query.get() won't be retrieved from cache.

https://developers.google.com/appengine/docs/python/ndb/缓存

来自文档:查询不会在任何缓存中查找值.但是,如果缓存策略这么说,查询结果会写回上下文缓存(但不会写回 Memcache).

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).

为了回答有关您将获得什么的问题,在两个查询中,结果似乎都是从数据存储区而不是从缓存中获取.

To answer the question regarding what you'll be getting, in both queries it appears that the results will be fetched from the datastore and not from cache.

这篇关于使用投影查询时的 NDB 缓存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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