cache

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 3, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultTTL      = 5 * time.Minute // Playlist refresh interval
	CleanupInterval = 1 * time.Minute // Expired entry cleanup
)

Default cache configuration

View Source
const (
	KeyMoodsList = "moods:list"
	KeyPlaylist  = "playlist:%s" // playlist:{mood}
)

Cache keys

Variables

This section is empty.

Functions

func PlaylistKey

func PlaylistKey(mood string) string

PlaylistKey returns the cache key for a mood's playlist.

Types

type Cache

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

Cache is a simple in-memory key-value store with TTL expiration.

func New

func New() (*Cache, error)

New creates a new cache that periodically evicts expired entries.

func (*Cache) Close

func (c *Cache) Close() error

Close stops the cleanup goroutine.

func (*Cache) Get

func (c *Cache) Get(key string) (any, bool)

Get retrieves a value from cache. Returns (nil, false) on miss or expiry.

func (*Cache) InvalidateMoods

func (c *Cache) InvalidateMoods()

InvalidateMoods clears all mood-related cache entries.

func (*Cache) Set

func (c *Cache) Set(key string, value any) error

Set stores a value with the default TTL.

func (*Cache) Stats

func (c *Cache) Stats() map[string]any

Stats returns cache statistics for the metrics endpoint.

Jump to

Keyboard shortcuts

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