filecache

package
v0.19.1064 Latest Latest
Warning

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

Go to latest
Published: Jul 15, 2026 License: AGPL-3.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FileCache

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

FileCache is a file-based LRU cache. It tracks files in memory and evicts the least recently used when count or total size limits are exceeded.

func New

func New(opts Options) (*FileCache, error)

New creates a new file-based LRU cache. The directory is created if it does not exist.

func (*FileCache) Get

func (c *FileCache) Get(id string) ([]byte, bool)

Get reads data from the cache and promotes the entry to most recently used. Returns (nil, false) on cache miss or read error. Nil-safe: calling Get on a nil *FileCache always returns (nil, false).

func (*FileCache) Has added in v0.19.1037

func (c *FileCache) Has(id string) bool

Has reports whether an entry is currently tracked and promotes it to most recently used. It does not read the file from disk, so it is cheaper than Get when only presence matters. A tracked entry implies the data was previously written to durable storage, so callers can safely skip re-uploading. Nil-safe: calling Has on a nil *FileCache returns false.

func (*FileCache) Len

func (c *FileCache) Len() int

Len returns the number of entries currently in the cache. Nil-safe: calling Len on a nil *FileCache returns 0.

func (*FileCache) Put

func (c *FileCache) Put(id string, data []byte) error

Put writes data to the cache atomically and evicts old entries if needed. Nil-safe: calling Put on a nil *FileCache is a no-op.

func (*FileCache) TotalSize

func (c *FileCache) TotalSize() int64

TotalSize returns the total size in bytes of all cached entries. Nil-safe: calling TotalSize on a nil *FileCache returns 0.

type Options

type Options struct {
	// Dir is the directory where cache files are stored.
	// Created if it does not exist.
	Dir string

	// MaxCount is the maximum number of files in the cache.
	// When exceeded, the least recently used files are evicted.
	MaxCount int

	// MaxBytes is the maximum total size in bytes of all cached files.
	// When exceeded, the least recently used files are evicted.
	MaxBytes int64
}

Jump to

Keyboard shortcuts

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