Skip to content

Commit

Permalink
fix use sync map
Browse files Browse the repository at this point in the history
  • Loading branch information
zhuxiujia committed Jun 10, 2020
1 parent d76d8cd commit 0aa663c
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions ExpressionEngineLexerMapCache.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,11 @@ import (
)

type ExpressionEngineLexerMapCache struct {
mapCache map[string]interface{}
mapCache sync.Map
lock sync.RWMutex
}

func (it ExpressionEngineLexerMapCache) New() ExpressionEngineLexerMapCache {
if it.mapCache == nil {
it.mapCache = make(map[string]interface{})
}
return it
}

Expand All @@ -23,14 +20,17 @@ func (it *ExpressionEngineLexerMapCache) Set(expression string, lexer interface{
}
it.lock.Lock()
defer it.lock.Unlock()
it.mapCache[expression] = lexer
it.mapCache.Store(expression, lexer)
return nil
}
func (it *ExpressionEngineLexerMapCache) Get(expression string) (interface{}, error) {
var result interface{}
it.lock.RLock()
defer it.lock.RUnlock()
result = it.mapCache[expression]
result, ok := it.mapCache.Load(expression)
if !ok {
return nil, nil
}
return result, nil
}
func (it *ExpressionEngineLexerMapCache) Name() string {
Expand Down

0 comments on commit 0aa663c

Please sign in to comment.