cache

package
v0.2.1-alpha Latest Latest
Warning

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

Go to latest
Published: Apr 27, 2026 License: GPL-3.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

type Cache[K comparable, V any] struct {
	// contains filtered or unexported fields
}

Cache is a generic, mutex-protected, LRU-evicting cache.

func New

func New[K comparable, V any](maxItems int) *Cache[K, V]

New creates a Cache with the given maximum capacity. Pass 0 for unlimited entries (no eviction).

func (*Cache[K, V]) Age

func (c *Cache[K, V]) Age(key K) time.Duration

Age returns the time since the entry was stored, or -1 if absent.

func (*Cache[K, V]) Delete

func (c *Cache[K, V]) Delete(key K)

Delete removes an entry.

func (*Cache[K, V]) Get

func (c *Cache[K, V]) Get(key K) *Entry[V]

Get returns the cached entry for key, or nil if absent.

func (*Cache[K, V]) Put

func (c *Cache[K, V]) Put(key K, value V)

Put stores a value, evicting the oldest entry if at capacity.

func (*Cache[K, V]) Size

func (c *Cache[K, V]) Size() int

Size returns the number of entries currently in the cache.

type DiskStore

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

DiskStore persists immutable build data to disk using gob encoding. Data is stored under dir, one file per domain.

Concurrency: a mutex guards all read-modify-write operations so multiple goroutines (completion cascade cmds) can call Save* concurrently.

func NewDiskStore

func NewDiskStore(dir string) (*DiskStore, error)

NewDiskStore creates a DiskStore rooted at dir, creating the directory if needed.

func (*DiskStore) LoadAllBuilds

func (d *DiskStore) LoadAllBuilds() ([]jenkins.UserBuild, error)

LoadAllBuilds reads all completed builds from disk.

func (*DiskStore) LoadJobs

func (d *DiskStore) LoadJobs(folderPath string) ([]jenkins.Job, error)

LoadJobs returns the cached job listing for the given folder path.

func (*DiskStore) LoadStages

func (d *DiskStore) LoadStages(key string) ([]jenkins.Stage, error)

LoadStages returns the cached stages for the given key ("jobPath:buildNum").

func (*DiskStore) LoadTestReport

func (d *DiskStore) LoadTestReport(key string) (*jenkins.TestReport, error)

LoadTestReport returns the cached test report for the given key ("jobPath:buildNum").

func (*DiskStore) SaveAllBuilds

func (d *DiskStore) SaveAllBuilds(builds []jenkins.UserBuild) error

SaveAllBuilds atomically writes the full build list to disk.

func (*DiskStore) SaveJobs

func (d *DiskStore) SaveJobs(folderPath string, jobs []jenkins.Job) error

SaveJobs persists the job listing for a single folder (read-modify-write).

func (*DiskStore) SaveStages

func (d *DiskStore) SaveStages(key string, stages []jenkins.Stage) error

SaveStages persists stages for a single build (read-modify-write on the shared map file).

func (*DiskStore) SaveTestReport

func (d *DiskStore) SaveTestReport(key string, report *jenkins.TestReport) error

SaveTestReport persists a test report for a single build (read-modify-write).

type Entry

type Entry[V any] struct {
	Value     V
	FetchedAt time.Time
}

Entry holds a cached value and the time it was stored.

type NodeLogSnapshot

type NodeLogSnapshot struct {
	Text      string
	NextStart int
	MoreData  bool
}

NodeLogSnapshot holds the progressive log state for a single flow node.

type StageLogKey

type StageLogKey struct {
	JobPath     string
	BuildNumber int
	NodeID      int
}

StageLogKey uniquely identifies a node log within a build.

type Store

type Store struct {
	Jobs          *Cache[string, []jenkins.Job]          // key: folderPath
	Builds        *Cache[string, []jenkins.Build]        // key: jobPath
	ProjectBuilds *Cache[string, []jenkins.ProjectBuild] // key: projectPath
	Stages        *Cache[string, []jenkins.Stage]        // key: "jobPath:buildNum"
	NodeLogs      *Cache[StageLogKey, NodeLogSnapshot]   // LRU(200)
	RunningBuilds *Cache[string, []jenkins.UserBuild]    // singleton key ""
	AllBuilds     *Cache[string, []jenkins.UserBuild]    // singleton key ""; from ScanAllBuilds
	WhenSkipped   *Cache[string, map[string][]bool]      // key: "jobPath:buildNum"
	TestReports   *Cache[string, *jenkins.TestReport]    // key: "jobPath:buildNum"
	BuildDetail   *Cache[string, jenkins.Build]          // key: "jobPath:buildNum"

	Disk *DiskStore // nil when disk persistence is disabled
	// contains filtered or unexported fields
}

Store is the app-wide cache container shared by all views.

func NewStore

func NewStore(disk *DiskStore) *Store

NewStore creates a Store with sensible defaults. disk may be nil to disable persistence.

func (*Store) ClearDirtyBuilds

func (s *Store) ClearDirtyBuilds(jobPath string)

ClearDirtyBuilds clears the dirty flag for jobPath.

func (*Store) ClearDirtyJobs

func (s *Store) ClearDirtyJobs(folderPath string)

ClearDirtyJobs clears the dirty flag for folderPath.

func (*Store) IsDirtyBuilds

func (s *Store) IsDirtyBuilds(jobPath string) bool

IsDirtyBuilds reports whether the Builds cache for jobPath is stale.

func (*Store) IsDirtyJobs

func (s *Store) IsDirtyJobs(folderPath string) bool

IsDirtyJobs reports whether the Jobs cache for folderPath is stale.

func (*Store) MarkBuildsDirty

func (s *Store) MarkBuildsDirty(jobPath string)

MarkBuildsDirty marks the Builds cache for jobPath as stale.

func (*Store) MarkJobsDirty

func (s *Store) MarkJobsDirty(folderPath string)

MarkJobsDirty marks the Jobs cache for folderPath as stale.

func (*Store) TotalEntries

func (s *Store) TotalEntries() int

TotalEntries returns the sum of all cache sizes across the store.

Jump to

Keyboard shortcuts

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