Does it make sense to overwrite get_by_key_name with another function that uses memcache to save on database queries? Like below? In this example the memcache key consists of only the entity key_name just to make it simple…
class Entity(db.Model):
@classmethod
def get_by_key_name(cls, key_name):
entity = memcache.get(key_name)
if entity is not None:
return entity
else:
entity = cls.__super__.get_by_key_name(key_name)
memcache.add(key_name, entity, 3600)
return entity
A better and neater solution would be to use NDB, which has built in support for memcache and instance memory caching.