为了账号安全,请及时绑定邮箱和手机立即绑定

带有任何过期时间的 Memcache 项目在使用 Go 的 Google App Engine

带有任何过期时间的 Memcache 项目在使用 Go 的 Google App Engine

Go
临摹微笑 2021-08-23 15:23:17
此代码片段:err = memcache.JSON.Set(c, &memcache.Item{    Key:        mkey,    Object:     &total,    Expiration: 600,})然后是第二次调用:_, err := memcache.JSON.Get(c, mkey, &total); ...导致缓存未命中。简单地将 Expiration 值更改为 0 会导致缓存命中,但是我无法控制项目何时到期。我是否误读了到期应该如何工作?
查看完整描述

1 回答

?
慕妹3242003

TA贡献1824条经验 获得超6个赞

由于memcache.Item确实使用了Time.Duration(纳秒),因此最好Expiration使用秒来指定字段:


 time.Second * 600

内存缓存文档提到:


// Expiration is the maximum duration that the item will stay

// in the cache.

// The zero value means the Item has no expiration time.

// Subsecond precision is ignored.

// This is not set when getting items.

Expiration time.Duration


查看完整回答
反对 回复 2021-08-23
  • 1 回答
  • 0 关注
  • 187 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号