完成gcache LRU基准测试

This commit is contained in:
john
2018-09-19 09:47:50 +08:00
parent d545587d47
commit 0669d6c4b3
7 changed files with 79 additions and 55 deletions

View File

@ -83,13 +83,13 @@ func (this *StringInterfaceMap) GetWithDefault(key string, value interface{}) in
func (this *StringInterfaceMap) GetOrSetFunc(key string, f func() interface{}) interface{} {
if v := this.Get(key); v == nil {
value := f()
this.mu.Lock()
defer this.mu.Unlock()
// 写锁二次检索确认
if v, ok := this.m[key]; !ok {
v = f()
this.m[key] = v
return v
this.m[key] = value
return value
} else {
return v
}