我正在尝试使用 Memcached 和 Enyim 客户端测试我的 AWS Elasticache 节点,但由于某种原因,到期时间似乎超出了 1 小时。
我使用此代码添加了数据:
_client.Store(StoreMode.Set, "testkey", "test", DateTime.Now.AddMinutes(1));
然后我尝试使用检索数据
var data = _client.Get<string>("testkey");
但是这永远不会检索数据。但是,如果我从现在起将到期时间更改为 61 分钟,它将存储数据 1 分钟。我已经用 TimeSpan 而不是 DateTime.Now 尝试过此操作,但遇到了同样的问题。
我还输出了正确的 DateTime.Now
值,并且我的 AWS 区域是 EU-West,与输出的 DateTime.Now
位于同一时区
最佳答案
使用起来会更安全:
_client.Store(StoreMode.Set, "testkey", "test", TimeSpan.FromMinutes(1.0));
这样,您就不会依赖于 DateTime 和 UTC。
关于c# - 使用 AWS Elasticache 和 Enyim memcached 客户端时 Memcache 过期时间为 1 小时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26015635/