cache

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Sep 21, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package cache wraps a registry.Discovery with a resilient read-through cache inspired by go-micro's registry cache. It adds, on top of the underlying discovery: singleflight deduplication of concurrent lookups, a service-level TTL and per-node TTL, stale-while-error degradation when the registry fails, and a minimum retry interval that throttles refresh attempts to avoid cache stampedes.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New(d registry.Discovery, opts ...Option) registry.Discovery

New wraps d with a resilient read-through cache.

Types

type Option

type Option func(*Options)

Option configures a cache.

func WithMinRetryInterval

func WithMinRetryInterval(d time.Duration) Option

WithMinRetryInterval sets the minimum interval between registry refresh attempts for a service.

func WithNodeTTL

func WithNodeTTL(d time.Duration) Option

WithNodeTTL sets the per-node cache TTL.

func WithNow

func WithNow(f func() time.Time) Option

WithNow overrides the clock used for TTL decisions, primarily for tests.

func WithTTL

func WithTTL(d time.Duration) Option

WithTTL sets the service-level cache TTL.

type Options

type Options struct {
	TTL              time.Duration
	NodeTTL          time.Duration
	MinRetryInterval time.Duration
	// Now is the clock used for TTL decisions; tests inject a fake clock. It
	// lives in Options (rather than a package-level variable) so concurrent
	// caches with different clocks never race.
	Now func() time.Time
}

Options holds cache tunables.

Jump to

Keyboard shortcuts

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