【问题标题】:incr operation for a key of memcache is getting reset in every hour对 memcache 键的 incr 操作每隔一小时就会重置一次
【发布时间】:2020-10-03 00:26:01
【问题描述】:

我在应用引擎 api 的 gae 中使用 memcache,它的文档没有提供任何设置到期时间的信息,但它每小时都会重置。 https://cloud.google.com/appengine/docs/standard/python/refdocs/google.appengine.api.memcache.html#google.appengine.api.memcache.Client.incr

from google.appengine.api import memcache
def count(key):
    newVal = memcache.incr(key,delta=1,initial_value=1)
    return newVal

我希望该值持续 2 天,我怎样才能达到相同的效果?

【问题讨论】:

    标签: python-2.7 google-app-engine caching memcached


    【解决方案1】:

    Memcached 是内存缓存。您永远无法确定缓存中的对象是否会保留在缓存中。

    发生这种情况的原因有很多。

    • 如果你的缓存已满,有人试图插入一个对象,memcache 将驱逐使用最少的那个
    • memcache 中有一个slab 的概念,其中相似大小的对象保存在一个slab 中。可能是您的缓存未满,但您的平板已满,并且正在驱逐对象。你可以阅读更多关于它的信息here
    • 另一个原因可能是,在较新版本的 memcache(我认为是 1.5.0 之后)中,memcache 已经开始驱逐长时间不使用的slab 并且新的slab 需要空间。

    底线是您不应该依赖 memcached 来存储您的数据。最好将数据源作为某个数据库并仅使用 memcached 作为缓存。

    希望对你有帮助

    【讨论】:

      猜你喜欢
      • 2020-04-26
      • 2023-03-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-02-08
      • 1970-01-01
      • 2017-12-10
      • 2017-06-20
      相关资源
      最近更新 更多