cache

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package cache persists GitHub Actions run timings and other API responses to disk and memory so repeated TUI and CLI invocations avoid refetching.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FilterRunsByCommit

func FilterRunsByCommit(runs []github.RunTiming, commitSHA string) []github.RunTiming

FilterRunsByCommit returns the runs matching commitSHA, exactly or by a shared 7-character prefix. An empty commitSHA returns runs unchanged.

func FilterRunsByConclusion

func FilterRunsByConclusion(runs []github.RunTiming, conclusion string) []github.RunTiming

FilterRunsByConclusion returns the runs with the given conclusion. An empty conclusion returns runs unchanged.

func GetLatestRunPerWorkflow

func GetLatestRunPerWorkflow(runs []github.RunTiming) []github.RunTiming

GetLatestRunPerWorkflow returns each workflow's most recently created run, sorted by workflow name.

func GetRunsInDateRange

func GetRunsInDateRange(runs []github.RunTiming, since, until time.Time) []github.RunTiming

GetRunsInDateRange returns the runs created within [since, until]. A zero since or until leaves that bound unenforced.

func MergeRuns added in v0.7.0

func MergeRuns(existing, newRuns []github.RunTiming) []github.RunTiming

MergeRuns combines existing and newRuns by RunID (newRuns wins on conflict) and returns them sorted oldest-first.

Types

type GHAPerfCache

type GHAPerfCache struct {
	UpdatedAt time.Time          `json:"updated_at"`
	Repo      string             `json:"repo"`
	Runs      []github.RunTiming `json:"runs"`
}

GHAPerfCache holds a repository's cached GitHub Actions run timings.

type GHAPerfCacheManager

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

GHAPerfCacheManager reads and writes GHAPerfCache files on disk, one JSON file per repository under its cache directory.

func NewGHAPerfCacheManager

func NewGHAPerfCacheManager(cacheDir string) (*GHAPerfCacheManager, error)

NewGHAPerfCacheManager creates the cache directory (defaulting to ~/.cache/gh-sweep/gha-perf when cacheDir is empty) and returns a manager for it.

func (*GHAPerfCacheManager) Clear

func (m *GHAPerfCacheManager) Clear(owner, repo string) error

Clear removes owner/repo's cache file, treating a missing file as success.

func (*GHAPerfCacheManager) ClearAll

func (m *GHAPerfCacheManager) ClearAll() error

ClearAll removes every cache file in the manager's cache directory, treating a missing directory as success.

func (*GHAPerfCacheManager) GetCachedRunIDs

func (m *GHAPerfCacheManager) GetCachedRunIDs(owner, repo string) (map[int]bool, error)

GetCachedRunIDs returns the set of run IDs currently cached for owner/repo.

func (*GHAPerfCacheManager) ListCaches

func (m *GHAPerfCacheManager) ListCaches() ([]string, error)

ListCaches returns the owner_repo identifiers of every cache file in the manager's cache directory.

func (*GHAPerfCacheManager) Load

func (m *GHAPerfCacheManager) Load(owner, repo string) (*GHAPerfCache, error)

Load reads owner/repo's cache file, returning an empty GHAPerfCache when none exists yet.

func (*GHAPerfCacheManager) Save

func (m *GHAPerfCacheManager) Save(owner, repo string, cache *GHAPerfCache) error

Save writes cache to owner/repo's cache file, stamping its UpdatedAt and Repo fields first.

func (*GHAPerfCacheManager) Stats

func (m *GHAPerfCacheManager) Stats(owner, repo string) (int, time.Time, error)

Stats returns the cached run count and last-updated time for owner/repo.

type MemoryManager

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

MemoryManager implements an in-memory cache (temporary, will use SQLite later).

func NewMemoryManager

func NewMemoryManager(ttl time.Duration) *MemoryManager

NewMemoryManager creates a new in-memory cache manager.

func (*MemoryManager) CleanExpired

func (m *MemoryManager) CleanExpired() error

CleanExpired removes all expired entries.

func (*MemoryManager) Clear

func (m *MemoryManager) Clear() error

Clear removes all entries from the cache.

func (*MemoryManager) Close

func (*MemoryManager) Close() error

Close does nothing for memory cache but implements the interface.

func (*MemoryManager) Delete

func (m *MemoryManager) Delete(key string) error

Delete removes a value from the cache.

func (*MemoryManager) Get

func (m *MemoryManager) Get(key string, dest any) (bool, error)

Get retrieves a value from the cache.

func (*MemoryManager) Set

func (m *MemoryManager) Set(key string, value any) error

Set stores a value in the cache.

func (*MemoryManager) Stats

func (m *MemoryManager) Stats() (int, int, error)

Stats returns cache statistics.

Jump to

Keyboard shortcuts

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