cache

package
v1.3.2 Latest Latest
Warning

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

Go to latest
Published: Apr 5, 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) Decr added in v1.3.1

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

Decr atomically decrements the integer value of a key by 1.

func (*Cache) DecrBy added in v1.3.1

func (c *Cache) DecrBy(ctx context.Context, cacheName, key string, delta int64) (int64, error)

DecrBy atomically decrements the integer value of a key by delta.

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) Expire added in v1.3.1

func (c *Cache) Expire(ctx context.Context, cacheName, key string, ttl time.Duration) error

Expire sets a TTL on an existing key.

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) GetTTL added in v1.3.1

func (c *Cache) GetTTL(ctx context.Context, cacheName, key string) (time.Duration, error)

GetTTL returns the remaining TTL for a key. Returns -1 if the key has no TTL.

func (*Cache) Incr added in v1.3.1

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

Incr atomically increments the integer value of a key by 1.

func (*Cache) IncrBy added in v1.3.1

func (c *Cache) IncrBy(ctx context.Context, cacheName, key string, delta int64) (int64, error)

IncrBy atomically increments the integer value of a key by delta.

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) Persist added in v1.3.1

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

Persist removes the TTL from a key, making it persistent.

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