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

file

package
v0.5.3 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2026 License: MIT Imports: 26 Imported by: 0

Documentation

Overview

Package file implements a bounded persistent cache under an owned os.Root. Atomic operations serialize across local processes per key shard; network filesystems are unsupported. Tags, batch deletion and distributed fill leases are not supplied. Store.Invalidate physically removes a namespace's records.

Index

Constants

View Source
const MaxPrune = cacheatomic.MaxPrune

Variables

This section is empty.

Functions

This section is empty.

Types

type Backend

type Backend struct {
	*cacheatomic.Backend
	// contains filtered or unexported fields
}

Backend's embedded implementation supplies only the capabilities it supports. Close prevents new operations, stops the pruner and waits for active filesystem work. Filesystem syscalls cannot be interrupted, but contention observes the caller's context. Reads take no lock: records are published by atomic rename, so a reader sees either the old or the new complete record.

func Open

func Open(ctx context.Context, config Config) (*Backend, error)

Open prepares and starts a backend, closing it if startup fails.

func Prepare

func Prepare(config Config) (*Backend, error)

Prepare validates configuration and constructs an unstarted backend without filesystem I/O.

func (*Backend) Access

func (b *Backend) Access(ctx context.Context, key cache.EntryKey, mode cacheatomic.Mode, change cacheatomic.Change) error

Access runs one atomic change under the key's shard lock. A write that does not fit first reclaims expired records (at most once per second per backend) and then retries; only a cache still full of live records rejects it.

func (*Backend) Close

func (b *Backend) Close(ctx context.Context) error

Close stops startup and pruning, rejects new operations, and waits for admitted work before closing the root. Context cancellation ends only the wait.

func (*Backend) Done

func (b *Backend) Done() <-chan struct{}

Done closes after shutdown has drained admitted work and closed the root.

func (*Backend) FlushNamespace

func (b *Backend) FlushNamespace(ctx context.Context, namespace cache.Namespace) (uint64, error)

FlushNamespace physically removes every readable record of namespace. It locks one shard at a time, so it is not a fence against concurrent writers.

func (*Backend) FoundryAdapter

func (*Backend) FoundryAdapter(frameworkadapter.Seal)

FoundryAdapter marks the backend as framework-owned adapter I/O.

func (*Backend) Inspect

func (b *Backend) Inspect(ctx context.Context, key cache.EntryKey, inspect cacheatomic.Inspection) (bool, error)

Inspect validates the envelope, payload size and checksum without decoding or buffering payloads. Expire streams a new atomic record under the key's shard lock. Corrupt and over-bound records are absent and are never modified.

func (*Backend) Prune

func (b *Backend) Prune(ctx context.Context, limit int) (int, error)

Prune deletes at most limit expired records and orphan publications.

func (*Backend) Read

func (b *Backend) Read(ctx context.Context, key cache.EntryKey, data bool) (*cacheatomic.Record, time.Time, error)

Read observes one record without a lock. Corrupt and over-bound records are misses. The returned time is the configured clock after the read.

func (*Backend) Start

func (b *Backend) Start(ctx context.Context) error

Start opens and initializes the root, counts its records and, when PruneInterval is positive, starts the owned background pruner.

func (*Backend) Sweep

func (b *Backend) Sweep(ctx context.Context, limit int) (PruneResult, error)

Sweep deletes at most limit expired records and orphan publications, skipping (and counting) corrupt records and foreign files instead of stopping. It locks one shard at a time, never the whole root. A complete pass recounts the usage estimate. The scan is bounded by twice MaxEntries plus MaxPrune files.

type Config

type Config struct {
	Root          string
	MaxEntries    int
	MaxBytes      int64
	MaxValueBytes int
	Sync          bool
	Clock         clock.Clock
	// PruneInterval runs automatic reclamation of expired records while the
	// backend is started. Zero disables it; otherwise 1s to 24h.
	PruneInterval time.Duration
	// Logger optionally receives redacted automatic-prune failures.
	Logger *slog.Logger
}

Config bounds physical record files and bytes (including record envelopes). A write never fails because of expired records: at capacity the backend first reclaims up to MaxPrune expired records, then rejects only if still full. Usage is an estimate maintained by this process and recounted by every prune pass, so processes sharing a root can briefly overshoot between passes. Roots must be existing trusted directories. Every process sharing a root must use the same bounds, synchronized clocks and the same Foundry version.

func DefaultConfig

func DefaultConfig(root string) Config

DefaultConfig returns persistent cache defaults for an existing trusted root directory.

func (Config) Validate

func (c Config) Validate() error

Validate checks capacity, root, clock, pruning interval, and supported operating system.

type PruneResult

type PruneResult = cacheatomic.PruneResult

PruneResult reports one bounded prune pass, including skipped corrupt records.

Jump to

Keyboard shortcuts

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