mrmo123
mrmo123

Reputation: 725

parse google app engine object in python

Is it possible to parse a google app engine object like so...

objects = db.GqlQuery('SELECT * FROM Database WHERE item='random'')
memcache.add('object', objects, 3600)
if object =='some condition':
  #here can I do a query on 'objects' without using GqlQuery
elif object =='something else':
  #do a different query than the one above

The idea is to store an object into memcache and then manipulate that object in different ways. This is to lighten the datastore reads. Thanks in advance!

Upvotes: 0

Views: 81

Answers (1)

Tim Hoffman
Tim Hoffman

Reputation: 12986

You can and everyone will find they do it. However there a bunch of things you need to consider.

  1. At the moment you are trying to store a query object and not the results in memcache. objects in your code is a query object. Use run, fetch etc to get some results.

  2. Manipulating the objects and storing in memcache without writing back will mean you will lose data etc. memcache is not a reliable storage mechanism on appengine (it is just a cache) and things can be evicted at any time.

  3. If your query is intended to return a single result, get the object by the key it is far more efficient and not a lot slower than memcache, compared with a query. (ndb will cache gets for you - see the next point)

  4. It looks like you are starting out with appengine, if you have not got an existing code base, start out with ndb rather than db. It is in my opinion a better library. ndb does a lot of caching for you (when using get()) in memcache and the request/instance.

Upvotes: 2

Related Questions