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> Jason Mooberry <jasonmoo@me.com>
Sergey Shepelev <temotor@gmail.com> Sergey Shepelev <temotor@gmail.com>
Alex Edwards <ajmedwards@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 { } else if e2 := x.(int); e2+2 != 3 {
t.Error("e (which should be 1) plus 2 does not equal 3; value:", e2) t.Error("e (which should be 1) plus 2 does not equal 3; value:", e2)
} }
if expiration.UnixNano() != tc.items["e"].Expiration { tmp, ok := tc.items.Load("e")
t.Error("expiration for e is not the correct time") 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() { if expiration.UnixNano() < time.Now().UnixNano() {
t.Error("expiration for e is in the past") t.Error("expiration for e is in the past")

View File

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