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 ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrInvalidOptions identifies invalid adapter construction. ErrInvalidOptions = errors.New("invalid cache service options") 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 ¶
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
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 ¶
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 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.