cacheservice

package
v2.0.0 Latest Latest
Warning

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

Go to latest
Published: Sep 30, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package cacheservice adapts explicit cache resources to the service lifecycle without hiding their concrete types.

A non-nil Shutdown transfers close ownership to the adapter; omitting it keeps the resource shared and guarantees the adapter never closes it. Startup validation and readiness are opt-in and use service-provided contexts. The adapter performs no retries, closes transferred resources once, and preserves validation and cleanup causes without formatting them.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrInvalidOptions identifies invalid adapter construction.
	ErrInvalidOptions = errors.New("invalid cache service options")
	// ErrUnavailable identifies a resource that has not started or is stopping.
	ErrUnavailable = errors.New("cache service resource unavailable")
)

Functions

This section is empty.

Types

type Adapter

type Adapter[R any] struct {
	// contains filtered or unexported fields
}

Adapter retains one explicit concrete resource and its lifecycle policy.

func New

func New[R any](options Options[R]) (*Adapter[R], error)

New validates and constructs an inert adapter.

func (*Adapter[R]) Component

func (adapter *Adapter[R]) Component() service.Component

Component returns the ordered service lifecycle component.

func (*Adapter[R]) Readiness

func (adapter *Adapter[R]) Readiness() (service.ReadinessCheck, bool)

Readiness returns the configured opt-in readiness check.

func (*Adapter[R]) Resource

func (adapter *Adapter[R]) Resource() R

Resource returns the exact caller-provided concrete resource.

type Check

type Check[R any] func(context.Context, R) error

Check evaluates whether a resource can accept new work.

type Options

type Options[R any] struct {
	// Name is the secret-safe component name.
	Name string
	// Resource is the caller-constructed cache or Valkey resource.
	Resource R
	// Startup optionally validates Resource.
	Startup Startup[R]
	// Readiness optionally checks whether Resource can accept new work.
	Readiness Check[R]
	// Shutdown transfers close ownership when non-nil.
	Shutdown Shutdown[R]
}

Options configure one cache lifecycle adapter.

type OptionsError

type OptionsError struct {
	Field  string
	Reason string
}

OptionsError identifies one rejected option.

func (*OptionsError) Error

func (err *OptionsError) Error() string

Error returns a secret-safe construction diagnostic.

func (*OptionsError) Unwrap

func (err *OptionsError) Unwrap() error

Unwrap exposes the stable option classification.

type Shutdown

type Shutdown[R any] func(context.Context, R) error

Shutdown releases an explicitly transferred resource.

type Startup

type Startup[R any] func(context.Context, R) error

Startup performs optional resource validation before startup succeeds.

type StartupError

type StartupError struct {
	// Validation is the startup-check failure.
	Validation error
	// Cleanup is an optional transferred-resource shutdown failure.
	Cleanup error
}

StartupError preserves validation and cleanup failures without formatting either potentially sensitive cause.

func (*StartupError) Error

func (err *StartupError) Error() string

Error returns a secret-safe startup diagnostic.

func (*StartupError) Unwrap

func (err *StartupError) Unwrap() []error

Unwrap preserves both causes for errors.Is and errors.As.

Jump to

Keyboard shortcuts

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