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

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

问题描述

找不到这个问题。



例如,如果我先执行预计查询,那么App Engine的NDB如何处理缓存?

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

...然后做一个常规查询... ...

  MyModel.query()。get()

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

解决方案

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



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



https://developers.google.com/appengine/docs/python/ndb/cache



从文档:
查询不会在任何缓存中查找值。但是,如果高速缓存策略如此说明(但从来不是Memcache),则查询结果会写回到上下文高速缓存中。为了回答有关您将要做什么的问题在这两个查询中,看起来结果都会从数据存储中获取,而不是从缓存中获取。


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

...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() will be cached and retrieved from cache, but query.get() won't be retrieved from cache.

https://developers.google.com/appengine/docs/python/ndb/cache

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天全站免登陆