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

心已入冬 提交于 2019-12-11 21:08:04

问题


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?


回答1:


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



回答2:


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.



来源:https://stackoverflow.com/questions/3392990/how-do-i-store-a-fetched-entity-in-memcache-for-app-engine

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!