cache: Add a "disabled" cache
This commit is contained in:
parent
b2a1ab61c9
commit
3f545efc95
3 changed files with 26 additions and 1 deletions
|
@ -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
2
cache/cache.go
vendored
|
@ -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
23
cache/disabled.go
vendored
Normal 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() {}
|
Loading…
Reference in a new issue