thanos-io/thanos · error
failed to create inmemory cache
Error message
failed to create inmemory cache
What it means
When the cache type is IN-MEMORY, the factory builds an in-process cache via cache.NewInMemoryCache; any construction error is wrapped as 'failed to create inmemory cache'. The in-memory cache constructor validates its own config (max sizes, item limits).
Solutions
- Check that max_size and max_size_items are non-negative and correctly formatted (e.g. 536870912 or 512MB)
- Remove backend-specific keys that do not belong to the IN-MEMORY provider
- Read the wrapped inner error for the exact invalid field
- Validate config against the docs at Thanos caching_bucket.md for your version
- Default the values (omit them) to let the library apply defaults
Example fix
// before
config:
caches:
chunks:
max_size: -1
// after
config:
caches:
chunks:
max_size: 512MB
max_size_items: 0 Defensive patterns
Strategy: validation
Validate before calling
if maxSize < 0 || maxSizeItems < 0 { return errors.New("in-memory cache sizes must be non-negative") } Try / catch
cb, err := storecache.NewCachingBucketFromYaml(yamlContent, logger, reg, bucket, router)
if err != nil {
if strings.Contains(err.Error(), "failed to create inmemory cache") {
return fmt.Errorf("in-memory cache config invalid (check max_size/max_size_items): %w", err)
}
return err
} Prevention
- Keep max_size and max_size_items non-negative
- Omit fields to use library defaults
- Do not mix memcached/redis keys under IN-MEMORY entries
When it happens
Trigger: CachingWithBackendConfig.Type == IN-MEMORY and NewInMemoryCache returns an error, typically due to invalid InMemoryCacheConfig values such as negative max_size or max_size_items, or an unmarshal failure of the backendConfig into the in-memory config.
Common situations: Setting max_size to a negative or unparseable size in the caching YAML, putting memcached-specific keys under an IN-MEMORY cache entry, or running a Thanos version where in-memory cache config options changed.
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
- failed to parse template
- failed to execute template
- error while parsing config for request logging
- getting http client config
- parsing http config YAML
AI-assisted analysis of thanos-io/thanos@35b8b99117 (2026-09-07).
Data as JSON: /api/errors/bbb218645cd49d32.
Report an issue: GitHub.
Appendix: source
Thrown at pkg/store/cache/caching_bucket_factory.go:121
cfg.CacheGetRange("chunks", nil, isTSDBChunkFile, config.ChunkSubrangeSize, config.ChunkObjectAttrsTTL, config.ChunkSubrangeTTL, config.MaxChunksGetRangeRequests)
cfg.CacheExists("meta.jsons", nil, isMetaFile, config.MetafileExistsTTL, config.MetafileDoesntExistTTL)
cfg.CacheGet("meta.jsons", nil, isMetaFile, int(config.MetafileMaxSize), config.MetafileContentTTL, config.MetafileExistsTTL, config.MetafileDoesntExistTTL)
// Cache Iter requests for root.
cfg.CacheIter("blocks-iter", nil, isBlocksRootDir, config.BlocksIterTTL, JSONIterCodec{}, cfgHash)
switch strings.ToUpper(string(config.Type)) {
case string(MemcachedBucketCacheProvider):
var memcached cacheutil.RemoteCacheClient
memcached, err := cacheutil.NewMemcachedClient(logger, "caching-bucket", backendConfig, reg)
if err != nil {
return nil, errors.Wrapf(err, "failed to create memcached client")
}
c = cache.NewMemcachedCache("caching-bucket", logger, memcached, reg)
case string(InMemoryBucketCacheProvider):
c, err = cache.NewInMemoryCache("caching-bucket", logger, reg, backendConfig)
if err != nil {
return nil, errors.Wrapf(err, "failed to create inmemory cache")
}
case string(GroupcacheBucketCacheProvider):
const basePath = "/_galaxycache/"
c, err = cache.NewGroupcache(logger, reg, backendConfig, basePath, r, bucket, cfg)
if err != nil {
return nil, errors.Wrap(err, "failed to create groupcache")
}
case string(RedisBucketCacheProvider):
redisCache, err := cacheutil.NewRedisClient(logger, "caching-bucket", backendConfig, reg)
if err != nil {
return nil, errors.Wrapf(err, "failed to create redis client")
}
c = cache.NewRedisCache("caching-bucket", logger, redisCache, reg)
default:
return nil, errors.Errorf("unsupported cache type: %s", config.Type)
}View on GitHub (pinned to 35b8b99117)