Reputation: 305
This code snippet:
err = memcache.JSON.Set(c, &memcache.Item{
Key: mkey,
Object: &total,
Expiration: 600,
})
followed by a second call with this:
_, err := memcache.JSON.Get(c, mkey, &total);
...results in a cache miss.
Simply changing the Expiration value to 0 results in cache hits, but then I can't control when the items expire.
Am I misreading how expiration is supposed to work?
Upvotes: 1
Views: 1235
Reputation: 1323553
Since the memcache.Item does use Time.Duration (nanosecond), it is best to specify the Expiration
field using seconds:
time.Second * 600
The memcache doc mentions:
// 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
Upvotes: 4