@@ -67,9 +67,8 @@ type TSDBPostingsCacheConfig struct {
67
67
}
68
68
69
69
type PostingsCacheConfig struct {
70
- MaxBytes int64 `yaml:"max_bytes"`
71
70
Ttl time.Duration `yaml:"ttl"`
72
- Enabled bool `yaml:"enabled "`
71
+ MaxBytes int64 `yaml:"max_bytes "`
73
72
}
74
73
75
74
func (cfg * TSDBPostingsCacheConfig ) RegisterFlagsWithPrefix (prefix string , f * flag.FlagSet ) {
@@ -80,8 +79,11 @@ func (cfg *TSDBPostingsCacheConfig) RegisterFlagsWithPrefix(prefix string, f *fl
80
79
// RegisterFlagsWithPrefix adds the flags required to config this to the given FlagSet
81
80
func (cfg * PostingsCacheConfig ) RegisterFlagsWithPrefix (prefix , block string , f * flag.FlagSet ) {
82
81
f .Int64Var (& cfg .MaxBytes , prefix + "expanded_postings_cache." + block + ".max-bytes" , 10 * 1024 * 1024 , "Max bytes for postings cache" )
83
- f .DurationVar (& cfg .Ttl , prefix + "expanded_postings_cache." + block + ".ttl" , 10 * time .Minute , "TTL for postings cache" )
84
- f .BoolVar (& cfg .Enabled , prefix + "expanded_postings_cache." + block + ".enabled" , false , "Whether the postings cache is enabled or not" )
82
+ f .DurationVar (& cfg .Ttl , prefix + "expanded_postings_cache." + block + ".ttl" , 0 , "TTL for postings cache, 0 to disable." )
83
+ }
84
+
85
+ func (cfg * PostingsCacheConfig ) Enabled () bool {
86
+ return cfg .Ttl > 0
85
87
}
86
88
87
89
type ExpandedPostingsCache interface {
@@ -160,7 +162,7 @@ func (c *BlocksPostingsForMatchersCache) fetchPostings(blockID ulid.ULID, ix tsd
160
162
}
161
163
162
164
// Let's bypass cache if not enabled
163
- if ! cache .cfg .Enabled {
165
+ if ! cache .cfg .Enabled () {
164
166
return func (ctx context.Context ) (index.Postings , error ) {
165
167
return tsdb .PostingsForMatchers (ctx , ix , ms ... )
166
168
}
@@ -304,7 +306,7 @@ func (c *fifoCache[V]) getPromiseForKey(k string, fetch func() (V, int64, error)
304
306
}
305
307
defer close (r .done )
306
308
307
- if ! c .cfg .Enabled {
309
+ if ! c .cfg .Enabled () {
308
310
r .v , _ , r .err = fetch ()
309
311
return r , false
310
312
}
0 commit comments