evictfs

package
v0.0.0-...-c199c2d Latest Latest
Warning

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

Go to latest
Published: Jan 22, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package evictfs provides a contextual filesystem wrapper that automatically evicts files based on configurable limits such as maximum file count or total size.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New(ctx context.Context, fsys contextual.FS, config Config) (contextual.FS, error)

New creates a new evictfs instance wrapping the provided fsys. It initializes the internal state by walking the existing files in fsys.

Types

type Config

type Config struct {
	// MaxFiles is the maximum number of files to keep in the filesystem.
	// If 0, no limit is enforced based on file count.
	MaxFiles int
	// MaxSize is the maximum total size (in bytes) of all files in the filesystem.
	// If 0, no limit is enforced based on total size.
	MaxSize int64
	// MaxAge is the maximum age of a file in the filesystem.
	// Files older than this threshold (based on AccessTime) will be deleted on access.
	// If 0, no limit is enforced based on age.
	MaxAge time.Duration

	// Metadata is a factory function that creates a new Metadata instance
	// for a file when it is first discovered or created.
	// If nil, it defaults to an LRU policy.
	Metadata func(fi contextual.FileInfo) Metadata
}

Config specifies the configuration for evictfs.

type Metadata

type Metadata interface {
	// Less returns true if this metadata has lower priority (should be evicted sooner)
	// than the other metadata.
	Less(other Metadata) bool
	// Update updates the metadata with new FileInfo when the file is accessed.
	Update(fi contextual.FileInfo)
	// Size returns the size of the file as tracked by this metadata.
	Size() int64
	// AccessTime returns the time when the file was last accessed.
	AccessTime() time.Time
}

Metadata represents the eviction-related metadata for a file. It allows custom eviction policies beyond simple LRU.

Jump to

Keyboard shortcuts

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