(filename string, cacheCfg enrichment.DataProvider)
| 140 | } |
| 141 | |
| 142 | func 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 |
| 187 | func UpdateRegexpCacheMetrics() { |
searching dependent graphs…