Skip to content

Commit b3aab73

Browse files
committed
cache#Get requires write lock. #19
1 parent 2d52e1a commit b3aab73

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

cache.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ var SelectorCacheMaxEntries = 50
1717
var (
1818
cacheOnce sync.Once
1919
cache *lru.Cache
20-
cacheMutex sync.RWMutex
20+
cacheMutex sync.Mutex
2121
)
2222

2323
func getQuery(expr string) (*xpath.Expr, error) {
@@ -27,14 +27,11 @@ func getQuery(expr string) (*xpath.Expr, error) {
2727
cacheOnce.Do(func() {
2828
cache = lru.New(SelectorCacheMaxEntries)
2929
})
30-
cacheMutex.RLock()
30+
cacheMutex.Lock()
31+
defer cacheMutex.Unlock()
3132
if v, ok := cache.Get(expr); ok {
32-
cacheMutex.RUnlock()
3333
return v.(*xpath.Expr), nil
3434
}
35-
cacheMutex.RUnlock()
36-
cacheMutex.Lock()
37-
defer cacheMutex.Unlock()
3835
v, err := xpath.Compile(expr)
3936
if err != nil {
4037
return nil, err

0 commit comments

Comments
 (0)