【问题标题】:How do I store a fetched entity in memcache for App Engine?如何将获取的实体存储在 App Engine 的内存缓存中?
【发布时间】:2011-03-24 12:10:57
【问题描述】:

因为 App Engine 中的每个新请求都会创建一个新的处理程序,所以我要更改和放置(使用 POST)的实体必须再次检索。这似乎很浪费,因为我之前已经用 GET 的信息填充了表单。

如何在 App Engine 的 memcache 中存储密钥、获取的实体或密钥/实体对?

【问题讨论】:

标签: python google-app-engine memcached tipfy


【解决方案1】:

来自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 将存储任何“可腌制”的内容。

您可以通过以下导入访问 memcache:

from google.appengine.api import memcache

【讨论】:

    【解决方案2】:

    我一直在开发一个simple library,它为数据存储实体启用不同的存储层,它允许您从数据存储、内存缓存或本地实例中获取模型。你可以试试看。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-10-05
      • 1970-01-01
      • 2017-06-23
      • 1970-01-01
      • 2017-10-28
      • 2010-12-03
      • 2014-07-24
      • 1970-01-01
      相关资源
      最近更新 更多