crowdsecurity/crowdsec · error
unknown cache strategy '%s'
Error message
unknown cache strategy '%s'
What it means
RegexpCacheInit configures a regexp cache (rafthrift/cache LRU/LFU/ARC builder) from a cache config. This error is thrown when the config's cache strategy string is not one of the recognized strategies, so no cache can be built.
Source
Thrown at pkg/exprhelpers/helpers.go:177
size = *cacheCfg.Size
}
gc := gcache.New(size)
strategy := "LRU"
if cacheCfg.Strategy != "" {
strategy = cacheCfg.Strategy
}
switch strategy {
case "LRU":
gc = gc.LRU()
case "LFU":
gc = gc.LFU()
case "ARC":
gc = gc.ARC()
default:
return fmt.Errorf("unknown cache strategy '%s'", strategy)
}
if cacheCfg.TTL != nil {
gc.Expiration(*cacheCfg.TTL)
}
cache := gc.Build()
dataFileRegexCache[filename] = cache
return nil
}
// UpdateCacheMetrics is called directly by the prom handler
func UpdateRegexpCacheMetrics() {
metrics.RegexpCacheMetrics.Reset()
for name := range dataFileRegexCache {
metrics.RegexpCacheMetrics.With(prometheus.Labels{"name": name}).Set(float64(dataFileRegexCache[name].Len(true)))View on GitHub (pinned to 909b515798)
Solutions
- Set the cache strategy to exactly "LRU", "LFU", or "ARC" (uppercase) in the config.
- Check for casing errors — the switch is case-sensitive, so "lru" fails.
- Consult the crowdsec docs for the supported strategy list rather than the underlying cache library's docs.
- Remove the strategy key to fall back to the default case if one exists in the surrounding code.
Example fix
// before (config)
cache: { strategy: "lru", size: 100 }
// after
cache: { strategy: "LRU", size: 100 } Defensive patterns
Strategy: validation
Validate before calling
switch strategy {
case "", "LRU", "LFU", "ARC":
// ok
default:
return fmt.Errorf("unsupported cache strategy %q", strategy)
} Prevention
- Only use LRU, LFU or ARC, spelled exactly and uppercase
- Centralize cache strategy values in a config constant/enum instead of free-text YAML
- Test config changes with cscli/crowdsec in a dev environment before rollout
When it happens
Trigger: Calling RegexpCacheInit with a cache config whose strategy field is e.g. "lru" (lowercase), "fifo", "none", or any misspelling — the switch only matches "LRU", "LFU", "ARC" (and the empty/default case above it).
Common situations: Typos or wrong casing in config YAML for regexp cache settings; copying cache config from another project with different strategy names; enabling a strategy the embedded cache library doesn't support.
Understand the failure class
Background: "Invalid value" and "allowed values are" config errors: what your library rejected and how to fix it — this error's family across 41 libraries.
Related errors
- path must start with /
- invalid auth_type: must be one of basic_auth, headers, mtls
- on_challenge hooks are only valid in-band, not under outofba
- empty cti key
- no listen_uri or listen_socket specified
AI-assisted analysis of crowdsecurity/crowdsec@909b515798 (2026-09-06).
Data as JSON: /api/errors/d37ef9302d88ab36.
Report an issue: GitHub.