This commit is contained in:
Дмитрий 2019-10-04 19:24:12 +00:00 committed by GitHub
commit d15f910d83
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 133 additions and 248 deletions

View File

@ -7,3 +7,4 @@ Dustin Sallings <dustin@spy.net>
Jason Mooberry <jasonmoo@me.com>
Sergey Shepelev <temotor@gmail.com>
Alex Edwards <ajmedwards@gmail.com>
Dmitry Medvedev <mr.vidmed@gmail.com>

369
cache.go

File diff suppressed because it is too large Load Diff

View File

@ -1762,8 +1762,12 @@ func TestGetWithExpiration(t *testing.T) {
} else if e2 := x.(int); e2+2 != 3 {
t.Error("e (which should be 1) plus 2 does not equal 3; value:", e2)
}
if expiration.UnixNano() != tc.items["e"].Expiration {
t.Error("expiration for e is not the correct time")
tmp, ok := tc.items.Load("e")
if ok {
e := tmp.(Item)
if expiration.UnixNano() != e.Expiration {
t.Error("expiration for e is not the correct time")
}
}
if expiration.UnixNano() < time.Now().UnixNano() {
t.Error("expiration for e is in the past")

View File

@ -8,6 +8,7 @@ import (
"os"
"runtime"
"time"
"sync"
)
// This is an experimental and unexported (for now) attempt at making a cache
@ -171,7 +172,7 @@ func newShardedCache(n int, de time.Duration) *shardedCache {
for i := 0; i < n; i++ {
c := &cache{
defaultExpiration: de,
items: map[string]Item{},
items: sync.Map{},
}
sc.cs[i] = c
}