cache

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Mar 21, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package cache provides a portable cache API with cross-cutting concerns.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

type Cache struct {
	// contains filtered or unexported fields
}

Cache is the portable cache type wrapping a driver with cross-cutting concerns.

func NewCache

func NewCache(d driver.Cache, opts ...Option) *Cache

NewCache creates a new portable Cache wrapping the given driver.

func (*Cache) CreateCache

func (c *Cache) CreateCache(ctx context.Context, config driver.CacheConfig) (*driver.CacheInfo, error)

CreateCache creates a new cache instance.

func (*Cache) Delete

func (c *Cache) Delete(ctx context.Context, cacheName, key string) error

Delete removes a value from the cache.

func (*Cache) DeleteCache

func (c *Cache) DeleteCache(ctx context.Context, name string) error

DeleteCache deletes a cache instance.

func (*Cache) FlushAll

func (c *Cache) FlushAll(ctx context.Context, cacheName string) error

FlushAll removes all items from the cache.

func (*Cache) Get

func (c *Cache) Get(ctx context.Context, cacheName, key string) (*driver.Item, error)

Get retrieves a value from the cache.

func (*Cache) GetCache

func (c *Cache) GetCache(ctx context.Context, name string) (*driver.CacheInfo, error)

GetCache retrieves cache instance info.

func (*Cache) Keys

func (c *Cache) Keys(ctx context.Context, cacheName, pattern string) ([]string, error)

Keys returns all keys matching the given pattern.

func (*Cache) ListCaches

func (c *Cache) ListCaches(ctx context.Context) ([]driver.CacheInfo, error)

ListCaches lists all cache instances.

func (*Cache) Set

func (c *Cache) Set(ctx context.Context, cacheName, key string, value []byte, ttl time.Duration) error

Set stores a value in the cache.

type Option

type Option func(*Cache)

Option configures a portable Cache.

func WithErrorInjection

func WithErrorInjection(i *inject.Injector) Option

WithErrorInjection sets the error injector.

func WithLatency

func WithLatency(d time.Duration) Option

WithLatency sets simulated latency.

func WithMetrics

func WithMetrics(m *metrics.Collector) Option

WithMetrics sets the metrics collector.

func WithRateLimiter

func WithRateLimiter(l *ratelimit.Limiter) Option

WithRateLimiter sets the rate limiter.

func WithRecorder

func WithRecorder(r *recorder.Recorder) Option

WithRecorder sets the recorder.

Directories

Path Synopsis
Package driver defines the interface for cache service implementations.
Package driver defines the interface for cache service implementations.

Jump to

Keyboard shortcuts

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