forked from zhuxiujia/GoMybatis
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExpressionEngineLexerMapCache.go
More file actions
38 lines (34 loc) · 917 Bytes
/
Copy pathExpressionEngineLexerMapCache.go
File metadata and controls
38 lines (34 loc) · 917 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package GoMybatis
import (
"github.com/zhuxiujia/GoMybatis/utils"
"sync"
)
type ExpressionEngineLexerMapCache struct {
mapCache sync.Map
lock sync.RWMutex
}
func (it ExpressionEngineLexerMapCache) New() ExpressionEngineLexerMapCache {
return it
}
func (it *ExpressionEngineLexerMapCache) Set(expression string, lexer interface{}) error {
if expression == "" {
return utils.NewError("ExpressionEngineLexerMapCache", "set lexerMap chache key can not be ''!")
}
it.lock.Lock()
defer it.lock.Unlock()
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, ok := it.mapCache.Load(expression)
if !ok {
return nil, nil
}
return result, nil
}
func (it *ExpressionEngineLexerMapCache) Name() string {
return "ExpressionEngineLexerMapCache"
}