NDB Caching When Using Projected Queries

最后都变了- 提交于 2019-12-01 10:35:24

问题


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?


回答1:


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.




回答2:


Projection query results are never cached. It would not be right if a get by key were to ever return a projection result. So no worries.



来源:https://stackoverflow.com/questions/12128424/ndb-caching-when-using-projected-queries

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!