How to refresh configuration entries kept in Google App Engine Datastore?

255 views Asked by At

I would like to keep some application configuration entries as entities in the datastore. Now, when I update these entries from the Datastore Viewer (development environment) or Google Cloud Platform Datastore user interface (production environment), the new values aren't seen by the application. This is because ndb caches the entities.

My (quite open) question is: what is your technique for keeping configuration entries in the datastore, updating them from Google's user interface, and also providing fresh values to the application?

I have thought of the following:

  1. Set a reasonable _memcache_timeout on the ndb.Model subclass which defines the configuration entries - but memcache usage is suboptimal in this case (unnecessary datastore reads are performed).

  2. Keep cache settings at maximum, but implement a flush operation in the admin area of the application to flush entities individually. This is tricky because you can't be sure of the actual cache key of the entity. But normally it should be _memcache_prefix + key.urlsafe(), where _memcache_prefix is defined in ndb.context module.

  3. Update all configuration entries from the admin area of the application, and don't use Google's datastore user interfaces - this requires extra effort.

1

There are 1 answers

2
Dan McGrath On BEST ANSWER

Option 1 - Most work

Implement your own admin module in App Engine using the NDB client libraries. If you make changes to the entity via your own app then it would naturally write the correct memcache key for you.

Option 2 - Trading cost for update delays

As you already suggested, reduce maximum cache age for the model. For example, in most cases allow a 1 hour period before changes are live is not an unreasonable.

Option 3 - Least work, but a bad idea at scale

Flush the entire cache via the Cloud Console for memcache.

Warning: If you run at significant scale this is a bad idea, as it could cause a huge spike in requests. For example, if you are running 1 million reads/second to datastore after a 90% cache hit rate, you could spike to 10 million reads/second immediately upon flush.