ntfy-alertmanager/cache/cache.go

31 lines
775 B
Go
Raw Permalink Normal View History

// Package cache includes a memory cache for ntfy-alertmanager.
package cache
import (
"fmt"
"strings"
"git.xenrox.net/~xenrox/ntfy-alertmanager/config"
)
// Cache is the interface that describes a cache for ntfy-alertmanager.
type Cache interface {
Set(fingerprint string, status string) error
Contains(fingerprint string, status string) (bool, error)
Cleanup()
}
// NewCache reads the cache configuration cfg and creates the cache.
func NewCache(cfg config.CacheConfig) (Cache, error) {
switch strings.ToLower(cfg.Type) {
case "memory":
return NewMemoryCache(cfg.Duration), nil
case "redis":
return NewRedisCache(cfg.RedisURL, cfg.Duration)
2023-07-12 19:13:09 +02:00
case "disabled":
return NewDisabledCache()
default:
return nil, fmt.Errorf("illegal type %q", cfg.Type)
}
}