0

Because each new request in App Engine creates a new Handler, the entity I'd like to alter and put (using POST) has to be retrieved again. This seems wasteful, since I've populated the form with the information from GET a moment earlier.

How do I store a key, fetched entity, or key/entity pair in memcache for App Engine?

Matt Norris
  • 8,596
  • 14
  • 59
  • 90
  • Here is a good memcache tutorial: http://blog.notdot.net/2009/9/Efficient-model-memcaching And for tipfy users, here is a good reference for using helper methods with memcache: http://www.tipfy.org/docs/api/tipfy.ext.db.html#tipfy.ext.db.get_entity_from_protobuf – Matt Norris Aug 04 '10 at 01:03

2 Answers2

3

From here:

def get_data():
    data = memcache.get("key")
    if data is not None:
        return data
    else:
        data = self.query_for_data()
        memcache.add("key", data, 60)
        return data

Memcache will store anything that is 'pickleable'.

You get access to memcache with the following import:

from google.appengine.api import memcache
sje397
  • 41,293
  • 8
  • 87
  • 103
0

I've been developing a simple library that enables different storage layers for datastore entities, it allows you to fetch models from datastore,memcache or local instance. You can give it a try.

Can Bascil
  • 938
  • 8
  • 16