cache

package
v0.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 19, 2023 License: AGPL-3.0 Imports: 7 Imported by: 0

Documentation

Overview

Package cache includes a memory cache for ntfy-alertmanager.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

type Cache interface {
	Set(fingerprint string, status string) error
	Contains(fingerprint string, status string) (bool, error)
	Cleanup()
}

Cache is the interface that describes a cache for ntfy-alertmanager.

func NewCache

func NewCache(cfg config.CacheConfig) (Cache, error)

NewCache reads the cache configuration cfg and creates the cache.

func NewDisabledCache

func NewDisabledCache() (Cache, error)

NewDisabledCache creates a new disabled cache.

func NewMemoryCache

func NewMemoryCache(d time.Duration) Cache

NewMemoryCache creates a in-memory cache.

func NewRedisCache

func NewRedisCache(redisURL string, d time.Duration) (Cache, error)

NewRedisCache creates a new redis cache/client.

type DisabledCache

type DisabledCache struct{}

DisabledCache is the disabled cache.

func (*DisabledCache) Cleanup

func (c *DisabledCache) Cleanup()

Cleanup is an empty function to implement the interface.

func (*DisabledCache) Contains

func (c *DisabledCache) Contains(_ string, _ string) (bool, error)

Contains is an empty function to implement the interface.

func (*DisabledCache) Set

func (c *DisabledCache) Set(_ string, _ string) error

Set is an empty function to implement the interface.

type MemoryCache

type MemoryCache struct {
	// contains filtered or unexported fields
}

MemoryCache is the in-memory cache.

func (*MemoryCache) Cleanup

func (c *MemoryCache) Cleanup()

Cleanup iterates over all alerts in the cache and removes them, if they are expired.

func (*MemoryCache) Contains

func (c *MemoryCache) Contains(fingerprint string, status string) (bool, error)

Contains checks if an alert with a given fingerprint is in the cache and if the status matches.

func (*MemoryCache) Set

func (c *MemoryCache) Set(fingerprint string, status string) error

Set saves an alert in the cache.

type RedisCache

type RedisCache struct {
	// contains filtered or unexported fields
}

RedisCache is the redis cache.

func (*RedisCache) Cleanup

func (c *RedisCache) Cleanup()

Cleanup is an empty function that is simply here to implement the interface. Redis does its own cleanup.

func (*RedisCache) Contains

func (c *RedisCache) Contains(fingerprint string, status string) (bool, error)

Contains checks if an alert with a given fingerprint is in the cache and if the status matches.

func (*RedisCache) Set

func (c *RedisCache) Set(fingerprint string, status string) error

Set saves an alert in the cache.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL