cache

package
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2024 License: GPL-3.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrorUnableToMarshalJSON        = errors.New("unable to marshal as JSON")
	ErrorUnableToEnsureCacheDir     = errors.New("unable to ensure cache-dir is present")
	ErrorUnableToWriteCache         = errors.New("unable to write data to cache file")
	ErrorUnableToOpenCacheFile      = errors.New("unable to open cache")
	ErrorUnableToReadCacheFile      = errors.New("unable to read cache")
	ErrorUnableToUnmarshalCacheFile = errors.New("unable to unmarshal JSON from cache-file")
	ErrorUnableToReadCachePath      = errors.New("unable to read from cache path")
)

Functions

func IsExpired

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

Returns if t is expired

Types

type Cache

type Cache[T any] struct {
	Path string
}

func New

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

New Cache where default path is os.TempDir()

func (*Cache[T]) Add

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

Add data as JSON-file into cache-dir, returns nil if success

func (*Cache[T]) Clear added in v0.0.5

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

func (*Cache[T]) Get

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

Get data from JSON-file from cache-dir, returns nil if no result

func (*Cache[T]) List added in v0.0.5

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

type Saved added in v0.0.5

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