filecache

package
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: May 6, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package filecache provides a local filesystem-backed implementation of cache.ReadWriterOf[blob.Entry] with persistent snapshots and immutable blob files.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func PrefixSplit added in v0.5.0

func PrefixSplit(lengths ...int) func(version string) []string

PrefixSplit creates a version path splitter that uses consecutive prefix lengths as nested directory names. For example PrefixSplit(1) uses the first character, and PrefixSplit(2, 2) matches the default layout.

Types

type Config added in v0.5.0

type Config[K comparable] struct {
	// IndexPolicy configures the in-memory index backend.
	IndexPolicy cache.Policy

	// RetentionPolicy configures blob-storage retention and eviction behavior.
	blob.RetentionPolicy

	// IndexShardFunc customizes shard selection in the typed in-memory index.
	IndexShardFunc func(K) uint64

	// SplitPath converts a version into nested path segments under data dir.
	// If nil, two 2-character prefix directories are used.
	SplitPath func(version string) []string
}

Config controls file-backed storage layout and index behavior.

func (Config[K]) Use added in v0.5.0

func (c Config[K]) Use(cfg *Config[K])

Use is a functional option to apply storage configuration.

type Storage

type Storage[K comparable] struct {
	// contains filtered or unexported fields
}

Storage is a local filesystem-backed blob storage.

func NewStorage

func NewStorage[K comparable](path string, options ...func(cfg *Config[K])) (*Storage[K], error)

NewStorage creates a local filesystem-backed blob storage.

func (*Storage[K]) Close

func (s *Storage[K]) Close() error

Close dumps the in-memory index and stops background jobs.

func (*Storage[K]) Delete

func (s *Storage[K]) Delete(ctx context.Context, key K) error

Delete deletes a blob entry by key.

func (*Storage[K]) Read

func (s *Storage[K]) Read(ctx context.Context, key K) (blob.Entry, error)

Read reads a blob entry by key.

func (*Storage[K]) Write

func (s *Storage[K]) Write(ctx context.Context, key K, entry blob.Entry) error

Write materializes a blob entry into local storage and updates the index.

func (*Storage[K]) WriteAndRead

func (s *Storage[K]) WriteAndRead(ctx context.Context, key K, entry blob.Entry) (_ blob.Entry, err error)

WriteAndRead materializes a blob entry into local storage, updates the index, and returns the stored entry.

Jump to

Keyboard shortcuts

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