Attila O.
Attila O.

Reputation: 16615

Get the Model context of a Key object in Datastore (App Engine)

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?

Upvotes: 0

Views: 273

Answers (1)

Will McCutchen
Will McCutchen

Reputation: 13117

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).

Upvotes: 3

Related Questions