From 3f545efc95344ae6da3ff56de0a22cdf63b29615 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thorben=20G=C3=BCnther?= Date: Wed, 12 Jul 2023 19:13:09 +0200 Subject: [PATCH] cache: Add a "disabled" cache --- README.md | 2 +- cache/cache.go | 2 ++ cache/disabled.go | 23 +++++++++++++++++++++++ 3 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 cache/disabled.go 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() {}