Help us shape the future of Go! Take the 2026 Go Developer Survey

cacheaccess

package
v0.1.0-beta.1 Latest Latest
Warning

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

Go to latest
Published: Aug 31, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultPersistenceInterval bounds foreground cache-access writes while
	// keeping the durable LRU order reasonably current across restarts.
	DefaultPersistenceInterval = time.Minute
)

Variables

View Source
var ErrLRUAccessUncertain = errors.New("cache access is not reliable enough for LRU eviction")

ErrLRUAccessUncertain means an access timestamp could not be retained or persisted. LRU eviction must remain paused for the rest of the process.

Functions

This section is empty.

Types

type Gate

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

Gate serializes cache opens and commits with physical deletion for the same object version. Idle entries are removed as soon as their last user exits.

func NewGate

func NewGate() *Gate

NewGate creates a cache read/delete gate.

func (*Gate) Commit

func (g *Gate) Commit(versionID string, commit func() error) error

Commit serializes a local cache commit with deletion for the same version.

func (*Gate) GuardDeletion

func (g *Gate) GuardDeletion(versionID string, remove func())

GuardDeletion waits for open bodies and serializes final checks and physical deletion for one version.

func (*Gate) Open

func (g *Gate) Open(
	versionID string,
	open func() (io.ReadCloser, *cache.ObjectInfo, error),
) (*OpenedCacheEntry, error)

Open protects a successful cache open until the returned body is closed.

type OpenedCacheEntry

type OpenedCacheEntry struct {
	Body io.ReadCloser
	Info *cache.ObjectInfo
}

OpenedCacheEntry keeps a cache entry protected from deletion until Body is closed.

type Store

type Store interface {
	RecordVersionCacheAccess(context.Context, string, time.Time) error
	RecordVersionCacheCommit(context.Context, string, time.Time) error
}

Store persists foreground cache access and cache commit metadata.

type Tracker

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

Tracker coalesces durable access-time writes and retains the latest exact in-process access used by LRU finalization.

func NewTracker

func NewTracker(persistenceInterval time.Duration, store Store) *Tracker

NewTracker creates a bounded foreground cache-access tracker.

func (*Tracker) FlushWhileGuarded

func (t *Tracker) FlushWhileGuarded(ctx context.Context, versionID string) error

FlushWhileGuarded persists one version's latest access. The caller must hold the version's cache gate.

func (*Tracker) Forget

func (t *Tracker) Forget(versionID string)

Forget removes tracking state after the cache entry is deleted or its version is permanently removed.

func (*Tracker) Latest

func (t *Tracker) Latest(versionID string) time.Time

Latest returns the latest exact in-process access for one version.

func (*Tracker) RecordAccess

func (t *Tracker) RecordAccess(
	ctx context.Context,
	versionID string,
	durableAccess *time.Time,
) error

RecordAccess records one successful foreground cache open.

func (*Tracker) RecordCommit

func (t *Tracker) RecordCommit(
	ctx context.Context,
	versionID string,
	durableAccess *time.Time,
) error

RecordCommit records a successful local cache commit and forces the presence and access metadata write.

func (*Tracker) Run

func (t *Tracker) Run(ctx context.Context, gate *Gate, logger *slog.Logger)

Run flushes coalesced access times and retires clean idle entries.

func (*Tracker) SafeForLRU

func (t *Tracker) SafeForLRU() bool

SafeForLRU reports whether all access timestamps that could affect LRU deletion are still represented in memory or durable storage.

Jump to

Keyboard shortcuts

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