cache

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 22, 2026 License: GPL-3.0 Imports: 6 Imported by: 0

Documentation

Overview

Package cache provides file-based caching for API responses.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNotFound is returned when a cache entry does not exist.
	ErrNotFound = errors.New("cache: failed to find cache")
)

Functions

This section is empty.

Types

type Cache

type Cache[T any] struct {
	Path string
}

Cache holds a Path where the cached files are stored.

func New

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

New returns a 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
}

Saved represents a cached item with its filename.

Jump to

Keyboard shortcuts

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