blobcache

package
v0.10.4 Latest Latest
Warning

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

Go to latest
Published: May 8, 2026 License: MIT Imports: 5 Imported by: 1 module, 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.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrStoreNotConfigured is returned when a cache operation requires a blob store.
	ErrStoreNotConfigured = errors.New("blob store is not configured")
	// ErrEntryNotFound is returned when a cache entry is missing.
	ErrEntryNotFound = errors.New("cache entry not found")
)

Functions

func Check added in v0.10.0

func Check(ctx context.Context, store Store) error

Check runs the optional blob store health check when implemented.

Types

type Cache

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

Cache provides cache-oriented operations over a blob store while leaving higher-level domain serialization and refresh policy to consumers.

func New

func New(store Store, namespace string, ttl time.Duration) *Cache

New constructs a cache view over a blob store.

func NewWithPolicy

func NewWithPolicy(store Store, namespace string, policy Policy) *Cache

NewWithPolicy constructs a cache view with an explicit cache policy.

func (*Cache) CleanExpired

func (c *Cache) CleanExpired(ctx context.Context) error

CleanExpired removes all expired cache entries according to the configured policy.

func (*Cache) Delete

func (c *Cache) Delete(ctx context.Context, key string) error

Delete removes one cache entry.

func (*Cache) DeleteNamespace

func (c *Cache) DeleteNamespace(ctx context.Context) error

DeleteNamespace clears the entire cache namespace.

func (*Cache) Dir

func (c *Cache) Dir() string

Dir returns the resolved blob store root directory when exposed by the backend.

func (*Cache) Get

func (c *Cache) Get(ctx context.Context, key string) (data []byte, meta Meta, ok bool, err error)

Get reads one cache entry.

func (*Cache) List

func (c *Cache) List(ctx context.Context) ([]Entry, error)

List returns cache entries with policy-derived timing info.

func (*Cache) Put

func (c *Cache) Put(ctx context.Context, key string, value []byte, opts PutOptions) (Meta, error)

Put stores one cache entry.

func (*Cache) TTL

func (c *Cache) TTL() time.Duration

TTL returns the cache time-to-live duration.

type Clock

type Clock interface {
	Now() time.Time
}

Clock provides time for cache policy calculations.

type Describer added in v0.10.0

type Describer interface {
	DescribeBlobStore() Info
}

Describer exposes optional diagnostics for a blob store backend.

type Entry added in v0.10.0

type Entry struct {
	Key       string
	Meta      Meta
	Age       time.Duration
	ExpiresIn time.Duration
}

Entry describes one cached blob entry together with TTL-derived timing.

type HealthChecker added in v0.10.0

type HealthChecker interface {
	CheckBlobStore(ctx context.Context) error
}

HealthChecker exposes an optional health check for a blob store backend.

type Info added in v0.10.0

type Info struct {
	Backend                 string
	Root                    string
	SupportsList            bool
	SupportsStream          bool
	SupportsDeleteNamespace bool
}

Info describes optional backend diagnostics exposed by a blob store.

func Describe added in v0.10.0

func Describe(store Store, fallbackBackend string) Info

Describe returns the optional backend diagnostics exposed by a blob store, applying a fallback backend name when the store omits one.

type Inspector added in v0.10.0

type Inspector interface {
	BlobStoreRootDir() string
}

Inspector exposes optional store details for diagnostics.

type Meta added in v0.10.0

type Meta struct {
	Size        int64
	UpdatedAt   time.Time
	ExpiresAt   *time.Time
	ETag        string
	ContentType string
	Metadata    map[string]string
}

Meta describes a stored blob object.

type Object

type Object struct {
	Key  string
	Meta Meta
}

Object describes a listed blob object.

type Policy

type Policy struct {
	TTL   time.Duration
	Clock Clock
}

Policy defines cache timing behavior over blob metadata.

type PutOptions

type PutOptions struct {
	ContentType string
	ExpiresAt   *time.Time
	Metadata    map[string]string
}

PutOptions controls how an entry is persisted by a Store.

type Store added in v0.10.0

type Store interface {
	Get(ctx context.Context, namespace, key string) ([]byte, bool, Meta, error)
	Put(ctx context.Context, namespace, key string, value []byte, opts PutOptions) (Meta, error)
	Open(ctx context.Context, namespace, key string) (io.ReadCloser, bool, Meta, error)
	PutStream(ctx context.Context, namespace, key string, r io.Reader, opts PutOptions) (Meta, error)
	Delete(ctx context.Context, namespace, key string) error
	DeleteNamespace(ctx context.Context, namespace string) error
	List(ctx context.Context, namespace string) ([]Object, error)
}

Store stores opaque binary objects addressed by namespace + key.

Consumers own key layout, serialization, TTL policy, and stale fallback semantics. Backends only persist bytes and metadata.

Thread-safety: implementations MUST be safe for concurrent use across goroutines, including Put + Get + Delete on the same (namespace, key) from multiple goroutines simultaneously. The contract test suite at pkg/cache/blobcache/contracttest exercises this guarantee — register a new backend against it before merging.

Cross-process safety is best-effort and backend-specific. The bundled diskblob backend serializes per-key writes via an in-process keyed mutex; multi-process protection requires either separate root_dir values or external coordination (advisory file locks, etc.).

Directories

Path Synopsis
Package contracttest provides a shared test suite that validates the blobcache.Store contract.
Package contracttest provides a shared test suite that validates the blobcache.Store contract.

Jump to

Keyboard shortcuts

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