ntfy-alertmanager/cache/cache.go
2023-07-12 19:13:47 +02:00

30 lines
775 B
Go

// 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)
case "disabled":
return NewDisabledCache()
default:
return nil, fmt.Errorf("illegal type %q", cfg.Type)
}
}