cache

package
v0.0.21 Latest Latest
Warning

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

Go to latest
Published: May 27, 2025 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const CACHE_VERSION = "v2"

Variables

View Source
var (

	// DefaultTTL is the default time-to-live for cached entries
	DefaultTTL = 24 * time.Hour

	// DefaultDir is the default cache directory
	DefaultDir string
)

Functions

func Clear

func Clear() error

Types

type Cache

type Cache[T any] struct {
	// contains filtered or unexported fields
}

Cache provides a generic caching mechanism

func New added in v0.0.6

func New[T any](kind string) *Cache[T]

func (*Cache[T]) Clear

func (c *Cache[T]) Clear() error

Clear removes all cached entries

func (*Cache[T]) GetOrSet

func (c *Cache[T]) GetOrSet(key string, fn func() (T, error), forceUpdate bool) (T, error)

GetOrSet retrieves a value from cache or stores it if it doesn't exist

func (*Cache[T]) SetDir

func (c *Cache[T]) SetDir(dir string) error

SetDir updates the cache directory

func (*Cache[T]) SetTTL

func (c *Cache[T]) SetTTL(d time.Duration)

SetTTL updates the cache TTL

type Entry

type Entry[T any] struct {
	Value     T
	CreatedAt time.Time
}

Entry represents a cached item

Jump to

Keyboard shortcuts

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