开发者

How do I store a fetched entity in memcache for App Engine?

开发者 https://www.devze.com 2023-01-10 11:31 出处:网络
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

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 m开发者_如何学Gooment earlier.

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


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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号