-
-
Notifications
You must be signed in to change notification settings - Fork 179
/
apq.go
48 lines (41 loc) · 830 Bytes
/
apq.go
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
39
40
41
42
43
44
45
46
47
48
package core
import (
"github.com/dosco/graphjin/core/internal/qcode"
lru "github.com/hashicorp/golang-lru"
)
type apqInfo struct {
op qcode.QType
name string
query string
}
type apqCache struct {
lruCache *lru.Cache
staticCache map[string]apqInfo
}
func (gj *GraphJin) initapqCache() error {
var err error
if gj.prod {
gj.apq.staticCache = make(map[string]apqInfo)
} else {
gj.apq.lruCache, err = lru.New(100)
}
return err
}
func (c apqCache) Get(key string) (apqInfo, bool) {
if c.staticCache != nil {
v, ok := c.staticCache[key]
return v, ok
}
if v, ok := c.lruCache.Get(key); ok {
return v.(apqInfo), ok
} else {
return apqInfo{}, ok
}
}
func (c apqCache) Set(key string, val apqInfo) {
if c.staticCache != nil {
c.staticCache[key] = val
} else {
c.lruCache.Add(key, val)
}
}