Jelajahi Sumber

fix: memcache atomic add invalid memory

luzhenqian 4 tahun lalu
induk
melakukan
90eb293486
1 mengubah file dengan 3 tambahan dan 2 penghapusan
  1. 3 2
      pkg/cache/memcache.go

+ 3 - 2
pkg/cache/memcache.go

@@ -4,7 +4,6 @@ import (
 	"container/list"
 	"sync"
 	"sync/atomic"
-	//"fmt"
 )
 
 // An AtomicInt is an int64 to be accessed atomically.
@@ -12,11 +11,11 @@ type AtomicInt int64
 
 // MemCache is an LRU cache. It is safe for concurrent access.
 type MemCache struct {
+	hits, gets  AtomicInt
 	mutex       sync.RWMutex
 	maxItemSize int
 	cacheList   *list.List
 	cache       map[interface{}]*list.Element
-	hits, gets  AtomicInt
 }
 
 type entry struct {
@@ -31,6 +30,8 @@ func NewMemCache(maxItemSize int) *MemCache {
 		maxItemSize: maxItemSize,
 		cacheList:   list.New(),
 		cache:       make(map[interface{}]*list.Element),
+		hits:        0,
+		gets:        0,
 	}
 }