cache

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2026 License: MIT Imports: 11 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

fs/cache

github.com/lfhy/compactfs/fs/cache 提供按对象键管理的编码对象 SSD 读缓存。 github.com/lfhy/compactfs/fs/cache/writer 提供原始 chunk 的持久缓存,包名为 writer,负责容量预留、脏数据 pin、重启恢复和 clean 数据淘汰。 github.com/lfhy/compactfs/fs/cache/reader 提供解码块内存缓存、并发加载合并与 有界预取,公开 Config、Stats、Cache 和 New。

三者由 fs/core 和命令组装层协调。父包不导入 reader/writer 子包;子包通过 fs/chunk 使用内容标识,避免形成 cache → reader/writer → chunk → cache 的循环依赖。

backend.NewAfero 还可通过 AferoOptions.Cache 复用父包,或用 CacheRoot/CacheBytes 创建独立的有界本地对象读缓存,见后端选项。backend 为缓存键隔离实例身份, 不将读缓存当成 raw 写回层;调用方可按需选择 core 的编码缓存或此对象缓存。

磁盘中的原始缓存继续位于 <cache>/writeback;backend 提交后保留的原始 数据仍可服务读取,仅在需要容量时淘汰。持久化边界和配置见 NVMe 写回缓存指导,完整目录关系见 项目结构说明。

Documentation

Overview

Package cache implements an optional SSD-backed cache for compressed chunks.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

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

func New

func New(root string, maxBytes int64) (*Cache, error)

func (*Cache) Get

func (c *Cache) Get(ctx context.Context, key string) ([]byte, bool, error)

func (*Cache) Open

func (c *Cache) Open(ctx context.Context, key string) (*os.File, bool, error)

Open returns an owned read-only fd to an immutable cached representation. Eviction may unlink its name after return without affecting this reader. A concurrent replacement likewise leaves the opened inode unchanged.

func (*Cache) Put

func (c *Cache) Put(ctx context.Context, key string, data []byte) error

func (*Cache) PutReader

func (c *Cache) PutReader(ctx context.Context, key string, source io.Reader, size int64) error

PutReader stores a complete immutable representation without requiring an additional whole-object byte buffer. The reader is consumed before return.

func (*Cache) Remove

func (c *Cache) Remove(key string) error

func (*Cache) Resize added in v1.0.3

func (c *Cache) Resize(capacity int64) error

Resize evicts only recoverable encoded objects; readers retain their own FD.

func (*Cache) Usage

func (c *Cache) Usage(ctx context.Context) (Usage, error)

Usage returns a filesystem-backed usage snapshot. It scans the directory so the result remains correct after a process restart, when the in-memory LRU index has not been rebuilt yet.

type Usage

type Usage struct {
	Bytes int64
	Files int64
}

Usage describes files currently present below a cache root.

func UsagePath

func UsagePath(ctx context.Context, root string) (Usage, error)

UsagePath returns usage for a cache directory without opening it. A missing optional cache directory is reported as empty.

Directories

Path Synopsis
Package reader provides a bounded, coalescing cache of immutable decoded chunks.
Package reader provides a bounded, coalescing cache of immutable decoded chunks.
Package writer provides a durable raw-chunk cache.
Package writer provides a durable raw-chunk cache.

Jump to

Keyboard shortcuts

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