cache

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jun 17, 2025 License: GPL-3.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrorUnableToReadCachePath = errors.New("unable to read from cache path")
)

Functions

func IsExpired

func IsExpired(t time.Time, now *time.Time) bool

Check if t is expired.

now defaults to time.Now

Types

type Cache

type Cache[T any] struct {
	Path string
}

A cache holds a Path where the cached files are stored.

func New

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

Returns new Cache.

path defaults to os.TempDir if empty ("")

func (*Cache[T]) Add

func (c *Cache[T]) Add(name string, data any) error

Add data to c.

The data is stored as a JSON-file with name as the filename.

func (*Cache[T]) Clear

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

Clear c cache.

func (*Cache[T]) Get

func (c *Cache[T]) Get(name string) (*T, error)

Get data from c cache by provided name.

Returns nil, nil if cache data doesn't exist.

func (*Cache[T]) List

func (c *Cache[T]) List() ([]Saved[T], error)

List all files in c cache.

type Saved

type Saved[T any] struct {
	Filename string
	Item     T
}

Jump to

Keyboard shortcuts

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