cache

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Jul 6, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DriverMemory = "memory"

	NoExpiration = -1 * time.Second
)

Variables

View Source
var (
	// ErrInvalidCacheDriver is returned when an unsupported cache driver is provided.
	ErrInvalidCacheDriver = errors.New("invalid cache driver")
)

Functions

This section is empty.

Types

type Cache

type Cache interface {
	// Get returns the value for the given key.
	Get(ctx context.Context, key string) (any, error)

	// GetByPattern returns all values matching the given key pattern.
	GetByPattern(ctx context.Context, keyPattern string) (map[string]any, error)

	// Set stores a value with the given key and TTL.
	Set(ctx context.Context, key string, value any, ttl time.Duration) error

	// Delete removes the value for the given key.
	Delete(ctx context.Context, key string) error
}

Cache defines a generic interface for cache operations.

func New

func New(config *Config) (Cache, error)

New returns a new cache client based on the provided configuration.

type Config

type Config struct {
	// Driver is the type of cache backend (e.g., "memory").
	Driver string `yaml:"driver" json:"driver"`

	// InMemory is the configuration for the in-memory cache backend.
	InMemory *inmemory.Config `yaml:"inmemory" json:"inmemory"`
}

Config is the configuration for the cache client.

func DefaultConfig

func DefaultConfig() Config

DefaultConfig returns a Config with sensible defaults for in-memory caching.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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