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

cacheaccess

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2026 License: Apache-2.0 Imports: 14 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
)
View Source
const (

	// DeletionWaitLimit bounds exclusive cache permit acquisition.
	DeletionWaitLimit = 30 * time.Second
)

Variables

View Source
var ErrDeletionBusy = errors.New("cache deletion permit wait limit exceeded")

ErrDeletionBusy reports that the deletion permit wait limit expired.

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 content cache key. Idle entries are removed as soon as their last user exits.

func NewGate

func NewGate() *Gate

NewGate creates a cache read/commit/delete gate.

func (*Gate) Commit

func (g *Gate) Commit(ctx context.Context, cacheKey string, commit func() error) error

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

func (*Gate) GuardDeletion

func (g *Gate) GuardDeletion(ctx context.Context, cacheKey string, remove func()) error

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

func (*Gate) HoldRead

func (g *Gate) HoldRead(ctx context.Context, cacheKey string) (func(), error)

HoldRead protects a cache entry from deletion across multiple opens. The returned release function is idempotent and must be called by the holder.

func (*Gate) HoldUpload added in v0.1.1

func (g *Gate) HoldUpload(ctx context.Context, uploadID string) (func(), error)

HoldUpload serializes publication and completion of one multipart upload.

func (*Gate) Open

func (g *Gate) Open(
	ctx context.Context,
	cacheKey string,
	open func() (io.ReadCloser, *cache.ObjectInfo, error),
) (*OpenedCacheEntry, error)

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

func (*Gate) TryHoldDeletion added in v0.1.1

func (g *Gate) TryHoldDeletion(cacheKey string) (func(), bool)

TryHoldDeletion acquires exclusive access without delaying active readers.

func (*Gate) TryHoldRead added in v0.1.1

func (g *Gate) TryHoldRead(cacheKey string) (func(), bool)

TryHoldRead acquires a read permit without queuing behind deletion.

func (*Gate) TryHoldUpload added in v0.1.1

func (g *Gate) TryHoldUpload(uploadID string) (func(), bool)

TryHoldUpload skips a multipart upload that is being changed by a request.

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 {
	RecordContentCacheAccess(context.Context, int64, time.Time) error
	RecordContentCacheCommit(context.Context, int64, time.Time) error
}

Store persists foreground cache access and cache commit metadata. Store persists cache recency. The unit is the content payload, because one cache file backs every version that shares those bytes.

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, contentID int64) error

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

func (*Tracker) Forget

func (t *Tracker) Forget(contentID int64)

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

func (*Tracker) Latest

func (t *Tracker) Latest(contentID int64) time.Time

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

func (*Tracker) RecordAccess

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

RecordAccess records one successful foreground cache open.

func (*Tracker) RecordCommit

func (t *Tracker) RecordCommit(
	ctx context.Context,
	contentID int64,
	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