gpt4 book ai didi

java - memcache究竟是如何清除过期数据的?

转载 作者:行者123 更新时间:2023-12-04 15:54:23 24 4
gpt4 key购买 nike

我正在使用 com.google.appengine.api.memcache.MemcacheService与 Google Memcache 配合使用。

存储值时,我将过期时间设置为 60 秒。但即使在几分钟后,该值仍会从缓存中返回。

使用内存缓存的代码:

// Config
int expirationSeconds = 60;
Expiration expiration = Expiration.byDeltaSeconds(expirationSeconds);
MemcacheService memcache = MemcacheServiceFactory.getMemcacheService();

// Write operation
memcache.put(id, value, expiration);

// Read operation
memcache.get(id);

我预计在这种情况下该值不存在,因为 Memcache documentation当有人试图检索它失败时,过期的项目将被删除

为什么过期值仍然从Memcache返回?

最佳答案

文档使用了两个词evictedremoved 可以理解为interchangeable但他们aren't :

By default, all values remain in the cache as long as possible, until evicted due to memory pressure, removed explicitly by the app, or made unavailable for another reason (such as an outage).

in the note here我们可以看到删除过程是如何工作的:

The actual removal of expired cache data is handled lazily. An expired item is removed when someone unsuccessfully tries to retrieve it.

在同一个地方,驱逐是这样解释的:

The value is evicted no later than this time, though it can be evicted earlier for other reasons. Increment the value stored for an existing key does not update its expiration time.

逐出 类似于软删除,其中值不可用但仍在 Memcache 中。 Removal 执行实际删除操作。

关于java - memcache究竟是如何清除过期数据的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52410061/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com