cache

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2026 License: MIT Imports: 8 Imported by: 1 module, 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 stores small JSON documents, per repository under <git-common-dir>/git-stack/ or in a directory of the caller's choosing, so that commands (and completion) can render instantly from the last known state.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Write

func Write[T any](s *Store, name string, v T) error

Write stores v under name atomically (temp file + rename).

Types

type State

type State int

State describes the freshness of a cached document.

const (
	// Missing: no document exists (or it could not be decoded).
	Missing State = iota
	// Stale: the document exists but is older than the TTL.
	Stale
	// Fresh: the document is within the TTL.
	Fresh
)

func Read

func Read[T any](s *Store, name string, ttl time.Duration) (T, State, time.Time, error)

Read loads name. A missing or undecodable file yields the zero value and Missing; a decodable one yields Stale or Fresh depending on ttl. The returned time is when the document was saved.

func (State) String

func (s State) String() string

type Store

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

Store is the cache directory of one repository.

func At added in v0.1.5

func At(dir string) *Store

At returns a store rooted at dir, for documents that belong to the user rather than to one repository. Nothing is created until Write.

func New

func New(repo git.Repo) *Store

New returns the store for repo. Nothing is created until Write.

func (*Store) Dir

func (s *Store) Dir() string

Dir returns the cache directory.

func (*Store) Path

func (s *Store) Path(name string) string

Path returns the file backing name.

func (*Store) Remove

func (s *Store) Remove(name string) error

Remove deletes name; a missing document is not an error.

Jump to

Keyboard shortcuts

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