How To Clear Cache For Specific Model In Ndb
Solution 1:
I would recommend just disabling the cache for those model classes that you have in duplicate; better be safe than sorry. This is easily done by putting
_use_memcache = False_use_cache = False
inside each ndb.Model subclass (i.e. before or after the property declarations). Docs for this are here: https://developers.google.com/appengine/docs/python/ndb/cache#policy_functions (look for the table towards the end).
If you really want to clear the cache only when you write an entity using a old db.Model subclass, instead of the above you can try the following (assume ent is a db.Model subclass instance):
ndbkey = ndb.Key.from_old_key(ent.key())
ndbkey.delete(use_datastore=False)
This deletes the key from memcache and from the context cache but does not delete it from the datastore. When you try to read it back using its NDB key (or even when it comes back as a query result), however, it will appear to be deleted until the current HTTP request handler finishes, and it will not use memcache for about 30 seconds.
Post a Comment for "How To Clear Cache For Specific Model In Ndb"