views:

61

answers:

1

I'd like to bypass some frequent queries by storing str(key) in memcache. When I get the encoded_key back from memcached, I can reconstruct the key with Key(encoded=encoded_key).

But how can I query the actual object from the key? A possibility would be to use

GqlQuery('SELECT * FROM ' + Key(encoded_key).kind() + \
    ' WHERE __key__ = ' + encoded_key)

but I'd rather not use GQL if possible. Is there a way of getting the object without using GQL?

+3  A: 

Are you just storing the result of str(key) in memcached? If so, when you get it back, you should be able to just do db.get(key) to get the entity to which it points.

db.get() will take either a db.Key object or the string representation of a db.Key object (or a list of keys or key strings).

Will McCutchen
Yay, thanks! I must have missed this useful piece of information while reading the API docs.
Attila Oláh