Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
lz1998 committed Mar 25, 2021
1 parent 60ea9a6 commit 43b421c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
10 changes: 5 additions & 5 deletions service/cache/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (

type LruCache struct {
*lru.Cache
mutex sync.Mutex
sync.Mutex
}

func NewLruCache(maxEntries int) *LruCache {
Expand All @@ -18,14 +18,14 @@ func NewLruCache(maxEntries int) *LruCache {
}

func (l *LruCache) Add(key lru.Key, value interface{}) {
l.mutex.Lock()
l.Lock()
l.Cache.Add(key, value)
l.mutex.Unlock()
l.Unlock()
}
func (l *LruCache) Get(key lru.Key) (value interface{}, ok bool) {
l.mutex.Lock()
l.Lock()
value, ok = l.Cache.Get(key)
l.mutex.Unlock()
l.Unlock()
return
}

Expand Down
2 changes: 1 addition & 1 deletion service/cache/cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ func TestLruCache_Add(t *testing.T) {
t.Logf("1: %+v %+v", v, ok)
lruCache.Add(11, 10)
lruCache.Add(13, 10)
lruCache.Add(14, 10)
v, ok = lruCache.Get(10)
t.Logf("2: %+v %+v", v, ok)
lruCache.Add(14, 10)
}

0 comments on commit 43b421c

Please sign in to comment.