I use Google App Engine with the webapp2 framework (Python).
Almost every request to my app needs to consider a few settings that are rarely changed. My current implementation has a class
class Settings(ndb.Model):
# a few ndb.KeyProperty and ndb.BooleanProperty types
and each requesthandler uses a function
def get_settings():
s = Settings.get_by_id('settings')
if not s:
s = Settings(id='settings')
s.put()
return s
to retrieve the single entity with ID 'settings'. NDB automatically stores this entity in memcache, so the function is quite fast, but today I discovered webapp2's registry attribute.
Is it a good idea to have
get_settingswrite the settings entity in the registry and try to retrieve it from there, using NDB/memcache only as a fallback?Is that what the registry is for? The documentation only has an example for a lazy import.