1
votes

I have a legacy app version (webapp2) that uses db to write to the datastore. I've written a new read-only flask API that uses ndb on the same datastore.

The writes via db are not cached for the ndb queries, which is the problem. I've found this workaround to disable cached reads for ndb, How to clear cache for specific model in NDB

But I was wondering if there was another way to guide to manage this, or is the solution a complete migration to ndb?

1

1 Answers

3
votes

No, it's not possible to use caching when both clients are active as the ndb client uses caching via memcache and the db client does not. From The Python DB Client Library for Cloud Datastore:

Note: Developers building new applications are strongly encouraged to use the NDB Client Library, which has several benefits compared to this client library, such as automatic entity caching via the Memcache API. If you are currently using the older DB Client Library, read the DB to NDB Migration Guide.

Attempting to use the ndb cache means that there may be differences between what each of the clients sees for the same entity.

Since db has been marked as deprecated for a while now, I'd rather take the time to make the migration to ndb, in most cases it's not such a big task. Aside from running with an officially supported solution you'd also get a performance improvement and possibly a cost reduction as well. IMHO well worthy.