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: 5 Imported by: 0

Documentation

Overview

Package cacheservice is the legacy cache service-lifecycle adapter.

Deprecated: use github.com/faustbrian/go-cache/v2/adapters/service. This package remains supported for the longer of 180 days after successor availability and two subsequently published stable root-module minor releases.

Index

Examples

Constants

This section is empty.

Variables

View Source
var (
	// ErrInvalidOptions identifies invalid adapter construction.
	ErrInvalidOptions = canonical.ErrInvalidOptions
	// ErrUnavailable identifies a resource that has not started or is stopping.
	ErrUnavailable = canonical.ErrUnavailable
)

Functions

This section is empty.

Types

type Adapter

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

Adapter preserves the legacy service adapter type identity.

func New

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

New validates and constructs an inert adapter.

Example
value := &resource{}
adapter, err := cacheservice.New(cacheservice.Options[*resource]{
	Name:     "cache",
	Resource: value,
	Readiness: func(context.Context, *resource) error {
		return nil
	},
})
if err != nil {
	fmt.Println("adapter setup failed")

	return
}

component := adapter.Component()
_ = component.Start(context.Background())
check, _ := adapter.Readiness()
_ = check.Run(context.Background())
_ = component.Stop(context.Background())

fmt.Println(adapter.Resource() == value)
Output:
true

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      string
	Resource  R
	Startup   Startup[R]
	Readiness Check[R]
	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 error
	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