store

package
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: May 22, 2026 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package store provides content-addressable storage implementations.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CAFS

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

CAFS implements content-addressable file storage. Content is stored in a sharded directory structure based on hash.

func NewCAFS

func NewCAFS(b backend.Backend, opts ...CAFSOption) *CAFS

NewCAFS creates a new content-addressable file store.

func (*CAFS) Delete

func (c *CAFS) Delete(ctx context.Context, h contentcache.Hash) error

Delete removes content by its hash.

func (*CAFS) Get

func (c *CAFS) Get(ctx context.Context, h contentcache.Hash) (io.ReadCloser, error)

Get retrieves content by its hash.

func (*CAFS) GetBytes

func (c *CAFS) GetBytes(ctx context.Context, h contentcache.Hash) ([]byte, error)

GetBytes is a convenience method for retrieving content as bytes.

func (*CAFS) GetFramed

GetFramed retrieves content with its headers.

func (*CAFS) Has

func (c *CAFS) Has(ctx context.Context, h contentcache.Hash) (bool, error)

Has checks if content with the given hash exists.

func (*CAFS) List

func (c *CAFS) List(ctx context.Context) ([]contentcache.Hash, error)

List returns all hashes in the store.

func (*CAFS) Put

func (c *CAFS) Put(ctx context.Context, r io.Reader) (contentcache.Hash, error)

Put stores content and returns its hash.

func (*CAFS) PutBytes

func (c *CAFS) PutBytes(ctx context.Context, data []byte) (contentcache.Hash, error)

PutBytes is a convenience method for storing bytes.

func (*CAFS) PutFramed

func (c *CAFS) PutFramed(ctx context.Context, header *backend.BlobHeader, body io.Reader) (contentcache.Hash, error)

PutFramed stores content with headers and returns its hash.

func (*CAFS) PutWithResult

func (c *CAFS) PutWithResult(ctx context.Context, r io.Reader) (*PutResult, error)

PutWithResult stores content and returns detailed information. Uses a temp file to avoid memory exhaustion for large content.

func (*CAFS) Size

func (c *CAFS) Size(ctx context.Context, h contentcache.Hash) (int64, error)

Size returns the size of content with the given hash.

type CAFSOption

type CAFSOption func(*CAFS)

CAFSOption configures a CAFS instance.

func WithEvictionNotifier

func WithEvictionNotifier(n EvictionNotifier) CAFSOption

WithEvictionNotifier wires an EvictionNotifier (e.g. the S3-FIFO Manager) into the CAFS so that admissions and external deletions are tracked.

func WithMetaDB

func WithMetaDB(db metadb.MetaDB) CAFSOption

WithMetaDB sets a MetaDB for blob tracking.

func WithMetadataTracker

func WithMetadataTracker(tracker MetadataTracker) CAFSOption

WithMetadataTracker sets a metadata tracker for expiration support.

type EvictionNotifier

type EvictionNotifier interface {
	// Admit is called when a new blob is stored for the first time.
	Admit(ctx context.Context, hash string, size int64)
	// Remove is called when a blob is deleted externally (GC, explicit Delete).
	// size is the blob's byte count for accurate accounting; 0 if unknown.
	Remove(ctx context.Context, hash string, size int64)
}

EvictionNotifier is notified of blob lifecycle events so that a cache eviction policy (e.g. S3-FIFO) can maintain its own state.

type ExtendedStore

type ExtendedStore interface {
	Store

	// PutWithResult stores content and returns detailed information.
	PutWithResult(ctx context.Context, r io.Reader) (*PutResult, error)

	// List returns all hashes in the store.
	// This may be expensive for large stores.
	List(ctx context.Context) ([]contentcache.Hash, error)
}

ExtendedStore provides additional operations beyond the basic Store.

type MetadataTracker

type MetadataTracker interface {
	// Create records metadata for a new blob.
	Create(ctx context.Context, hash contentcache.Hash, size int64) error
	// Touch updates the last access time for a blob.
	Touch(ctx context.Context, hash contentcache.Hash) error
	// Delete removes metadata for a blob.
	Delete(ctx context.Context, hash contentcache.Hash) error
}

MetadataTracker tracks blob metadata for expiration.

type PutResult

type PutResult struct {
	Hash   contentcache.Hash
	Size   int64
	Exists bool // true if the content already existed
}

PutResult contains information about a Put operation.

type Store

type Store interface {
	// Put stores content and returns its hash.
	// If the content already exists (same hash), this is a no-op.
	Put(ctx context.Context, r io.Reader) (contentcache.Hash, error)

	// Get retrieves content by its hash.
	// Returns ErrNotFound if the hash does not exist.
	// The caller must close the returned ReadCloser.
	Get(ctx context.Context, h contentcache.Hash) (io.ReadCloser, error)

	// Has checks if content with the given hash exists.
	Has(ctx context.Context, h contentcache.Hash) (bool, error)

	// Delete removes content by its hash.
	// Returns nil if the content does not exist (idempotent).
	Delete(ctx context.Context, h contentcache.Hash) error

	// Size returns the size of content with the given hash.
	// Returns ErrNotFound if the hash does not exist.
	Size(ctx context.Context, h contentcache.Hash) (int64, error)
}

Store provides content-addressable storage operations. Content is stored by its BLAKE3 hash, ensuring deduplication.

Directories

Path Synopsis
Package gc provides garbage collection for the content cache.
Package gc provides garbage collection for the content cache.
Package metadb provides metadata storage using bbolt for the content cache.
Package metadb provides metadata storage using bbolt for the content cache.
Package s3fifo implements the S3-FIFO cache eviction algorithm.
Package s3fifo implements the S3-FIFO cache eviction algorithm.

Jump to

Keyboard shortcuts

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