diff --git a/README.md b/README.md index 5ea7e07..b2b3d89 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/cache/cache.go b/cache/cache.go index dfea537..fecc16d 100644 --- a/cache/cache.go +++ b/cache/cache.go @@ -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) } diff --git a/cache/disabled.go b/cache/disabled.go new file mode 100644 index 0000000..91d9a8f --- /dev/null +++ b/cache/disabled.go @@ -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() {}