cache

package
v0.0.0-...-9208c1c Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2026 License: MIT Imports: 8 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package cache is an on-disk cache (contract C8 v1).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FileStore

type FileStore struct{ Dir string }

FileStore keeps values in <Dir>/<key>.json.

func NewFileStore

func NewFileStore(dir string) *FileStore

NewFileStore creates a store; the directory is created on the first Save.

func (*FileStore) Load

func (s *FileStore) Load(key string, v any) (time.Time, bool, error)

Load reads a value; a missing file, corruption or a foreign version give ok=false.

func (*FileStore) Save

func (s *FileStore) Save(key string, v any) error

Save writes a value atomically (renameio: temp+fsync+rename, mode 0600).

type Mem

type Mem struct {
	// contains filtered or unexported fields
}

Mem is an in-memory store for consumers' tests.

func NewMem

func NewMem(now func() time.Time) *Mem

NewMem creates a Mem; now supplies the save time (nil → time.Now).

func (*Mem) Load

func (m *Mem) Load(key string, v any) (time.Time, bool, error)

func (*Mem) Save

func (m *Mem) Save(key string, v any) error

type Store

type Store interface {
	// Load: missing file, corrupt file or foreign version → ok=false, err=nil.
	Load(key string, v any) (saved time.Time, ok bool, err error)
	Save(key string, v any) error
}

Store holds JSON-serializable values by key.

Jump to

Keyboard shortcuts

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