MCPcopy Create free account
hub / github.com/antchfx/htmlquery / getQuery

Function getQuery

cache.go:23–42  ·  view source on GitHub ↗
(expr string)

Source from the content-addressed store, hash-verified

21)
22
23func getQuery(expr string) (*xpath.Expr, error) {
24 if DisableSelectorCache || SelectorCacheMaxEntries <= 0 {
25 return xpath.Compile(expr)
26 }
27 cacheOnce.Do(func() {
28 cache = lru.New(SelectorCacheMaxEntries)
29 })
30 cacheMutex.Lock()
31 defer cacheMutex.Unlock()
32 if v, ok := cache.Get(expr); ok {
33 return v.(*xpath.Expr), nil
34 }
35 v, err := xpath.Compile(expr)
36 if err != nil {
37 return nil, err
38 }
39 cache.Add(expr, v)
40 return v, nil
41
42}

Callers 5

QueryAllFunction · 0.85
QueryFunction · 0.85
BenchmarkSelectorCacheFunction · 0.85
TestSelectorCacheFunction · 0.85

Calls

no outgoing calls

Tested by 3

BenchmarkSelectorCacheFunction · 0.68
TestSelectorCacheFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…