Unexpected behavior caching time.Time values
jwineinger opened this issue · 1 comments
jwineinger commented
Should I expect that I can include time.Time values in objects being cached? I'm seeing strange behavior
where the retrieved value is not the same as the cached value.
thanks!
func TestLocalCache(t *testing.T) {
type Object struct {
Num int
Expiry time.Time
}
mycache := cache.New(&cache.Options{
LocalCache: cache.NewTinyLFU(1000, time.Minute),
})
ctx := context.TODO()
key := "mykey"
myTime := time.Now()
obj := &Object{
Expiry: myTime,
Num: 42,
}
if err := mycache.Set(&cache.Item{
Ctx: ctx,
Key: key,
Value: obj,
TTL: time.Hour,
}); err != nil {
panic(err)
}
var wanted Object
if err := mycache.Get(ctx, key, &wanted); err != nil {
panic(err)
}
assert.Equal(t, myTime, wanted.Expiry)
}
=== RUN TestLocalCache
TestLocalCache: ...
Error Trace: ...
Error: Not equal:
expected: time.Time{wall:0xbfee6e9501f40bb8, ext:11320675, loc:(*time.Location)(0x2cd1e00)}
actual : time.Time{wall:0x1f40bb8, ext:63743670740, loc:(*time.Location)(0x2cd1e00)}
Diff:
--- Expected
+++ Actual
@@ -1,4 +1,4 @@
(time.Time) {
- wall: (uint64) 13830113091963325368,
- ext: (int64) 11320675,
+ wall: (uint64) 32771000,
+ ext: (int64) 63743670740,
loc: (*time.Location)({
Test: TestLocalCache
--- FAIL: TestLocalCache (0.00s)
Expected :time.Time{wall:0xbfee6e9501f40bb8, ext:11320675, loc:(*time.Location)(0x2cd1e00)}
Actual :time.Time{wall:0x1f40bb8, ext:63743670740, loc:(*time.Location)(0x2cd1e00)}
vmihailenco commented
Does it work with assert.True(t, myTime.Equal(wanted.Expiry))
?