cache: Add a "disabled" cache

This commit is contained in:
Thorben Günther 2023-07-12 19:13:09 +02:00
parent b2a1ab61c9
commit 3f545efc95
No known key found for this signature in database
GPG key ID: 415CD778D8C5AFED
3 changed files with 26 additions and 1 deletions

View file

@ -104,7 +104,7 @@ alertmanager {
# When the alert-mode is set to single, ntfy-alertmanager will cache each single alert
# to avoid sending recurrences.
cache {
# The type of cache that will be used (either memory or redis; default is memory).
# The type of cache that will be used (either disabled, memory or redis; default is memory).
type memory
# How long messages stay in the cache for
duration 24h

2
cache/cache.go vendored
View file

@ -22,6 +22,8 @@ func NewCache(cfg config.CacheConfig) (Cache, error) {
return NewMemoryCache(cfg.Duration), nil
case "redis":
return NewRedisCache(cfg.RedisURL, cfg.Duration)
case "disabled":
return NewDisabledCache()
default:
return nil, fmt.Errorf("illegal type %q", cfg.Type)
}

23
cache/disabled.go vendored Normal file
View file

@ -0,0 +1,23 @@
package cache
// DisabledCache is the disabled cache.
type DisabledCache struct{}
// NewDisabledCache creates a new disabled cache.
func NewDisabledCache() (Cache, error) {
c := new(DisabledCache)
return c, nil
}
// Set is an empty function to implement the interface.
func (c *DisabledCache) Set(_ string, _ string) error {
return nil
}
// Contains is an empty function to implement the interface.
func (c *DisabledCache) Contains(_ string, _ string) (bool, error) {
return false, nil
}
// Cleanup is an empty function to implement the interface.
func (c *DisabledCache) Cleanup() {}