To reduce datastore reading and writing, people suggest using memcache:
Write:
entity.put()
memcache.set(entity.key.id(), entity)
Read:
# id known:
entity = memcache.get(id)
if entity is None:
entity = Model.get_by_id(id)
memcache.set(id, entity)
I'd like to implement the above as two functions:
def memPut(entity):
entity.put()
memcache.set(entity.key.id(), entity)
def memGet(Model, id):
entity = memcache.get(id)
if entity is None:
entity = Model.get_by_id(id)
memcache.set(id, entity)
memGet
is just hypothetical. My questions: 1) how do I pass the name of the Model to the function as an parameter? 2) If an entity is created without specifying an id, GAE will use an integer as its id. What if there are two entities (of course from different models) having the same id? Would memcache.get(id) work?