cache

package
v0.0.0 Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2025 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

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

Clear removes all cached entries

func GetOrSet

func GetOrSet(key string, fn func() (string, error), forceUpdate bool) (string, error)

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

func SetDir

func SetDir(dir string) error

SetDir updates the cache directory

func SetTTL

func SetTTL(d time.Duration)

SetTTL updates the cache TTL

Types

type Cache

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

Cache provides a generic caching mechanism

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