MCPcopy
hub / github.com/crowdsecurity/crowdsec / RegexpCacheInit

Function RegexpCacheInit

pkg/exprhelpers/helpers.go:142–184  ·  view source on GitHub ↗
(filename string, cacheCfg enrichment.DataProvider)

Source from the content-addressed store, hash-verified

140}
141
142func RegexpCacheInit(filename string, cacheCfg enrichment.DataProvider) error {
143 // cache is explicitly disabled
144 if cacheCfg.Cache != nil && !*cacheCfg.Cache {
145 return nil
146 }
147 // cache is implicitly disabled if no cache config is provided
148 if cacheCfg.Strategy == "" && cacheCfg.TTL == nil && cacheCfg.Size == nil {
149 return nil
150 }
151 // cache is enabled
152
153 size := 50
154 if cacheCfg.Size != nil {
155 size = *cacheCfg.Size
156 }
157
158 gc := gcache.New(size)
159
160 strategy := "LRU"
161 if cacheCfg.Strategy != "" {
162 strategy = cacheCfg.Strategy
163 }
164
165 switch strategy {
166 case "LRU":
167 gc = gc.LRU()
168 case "LFU":
169 gc = gc.LFU()
170 case "ARC":
171 gc = gc.ARC()
172 default:
173 return fmt.Errorf("unknown cache strategy '%s'", strategy)
174 }
175
176 if cacheCfg.TTL != nil {
177 gc.Expiration(*cacheCfg.TTL)
178 }
179
180 cache := gc.Build()
181 dataFileRegexCache[filename] = cache
182
183 return nil
184}
185
186// UpdateCacheMetrics is called directly by the prom handler
187func UpdateRegexpCacheMetrics() {

Callers 3

processStageFileFunction · 0.92
initDataFilesMethod · 0.92
TestRegexpCacheBehaviorFunction · 0.85

Calls 1

BuildMethod · 0.45

Tested by 1

TestRegexpCacheBehaviorFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…