NDB query fetch() and ContextOptions

后端 未结 2 1931
庸人自扰
庸人自扰 2021-01-21 11:16

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=ContextOp         


        
2条回答
  •  野性不改
    2021-01-21 11:44

    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.

提交回复
热议问题