File tree Expand file tree Collapse file tree 2 files changed +9
-5
lines changed Expand file tree Collapse file tree 2 files changed +9
-5
lines changed Original file line number Diff line number Diff line change 1
1
package db
2
2
3
- import "github.com/zu1k/nali/pkg/dbif"
3
+ import (
4
+ "sync"
5
+
6
+ "github.com/zu1k/nali/pkg/dbif"
7
+ )
4
8
5
9
var (
6
10
dbNameCache = make (map [string ]dbif.DB )
7
11
dbTypeCache = make (map [dbif.QueryType ]dbif.DB )
8
- queryCache = make ( map [ string ] string )
12
+ queryCache = sync. Map {}
9
13
)
10
14
11
15
var (
Original file line number Diff line number Diff line change @@ -70,14 +70,14 @@ func GetDB(typ dbif.QueryType) (db dbif.DB) {
70
70
}
71
71
72
72
func Find (typ dbif.QueryType , query string ) string {
73
- if result , found := queryCache [ query ] ; found {
74
- return result
73
+ if result , found := queryCache . Load ( query ) ; found {
74
+ return result .( string )
75
75
}
76
76
result , err := GetDB (typ ).Find (query )
77
77
if err != nil {
78
78
return ""
79
79
}
80
80
r := strings .Trim (result .String (), " " )
81
- queryCache [ query ] = r
81
+ queryCache . Store ( query , r )
82
82
return r
83
83
}
You can’t perform that action at this time.
0 commit comments