Update xpath dependency (#507)

This commit is contained in:
WithoutPants
2020-04-30 08:32:33 +10:00
committed by GitHub
parent 3d22d5a742
commit 2166caf322
288 changed files with 34566 additions and 82048 deletions

View File

@@ -3,9 +3,8 @@ package htmlquery
import (
"sync"
"github.com/golang/groupcache/lru"
"github.com/antchfx/xpath"
"github.com/golang/groupcache/lru"
)
// DisableSelectorCache will disable caching for the query selector if value is true.
@@ -16,8 +15,9 @@ var DisableSelectorCache = false
var SelectorCacheMaxEntries = 50
var (
cacheOnce sync.Once
cache *lru.Cache
cacheOnce sync.Once
cache *lru.Cache
cacheMutex sync.Mutex
)
func getQuery(expr string) (*xpath.Expr, error) {
@@ -25,8 +25,10 @@ func getQuery(expr string) (*xpath.Expr, error) {
return xpath.Compile(expr)
}
cacheOnce.Do(func() {
cache = lru.New(50)
cache = lru.New(SelectorCacheMaxEntries)
})
cacheMutex.Lock()
defer cacheMutex.Unlock()
if v, ok := cache.Get(expr); ok {
return v.(*xpath.Expr), nil
}