adapter

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package adapter provides concrete core/cache.ExternalCache implementations for the external cache's supported backends: Redis (RedisCache) and Memcached (MemcachedCache). cache.NewExternal selects and constructs one of these from Options; nothing downstream of that composition point imports this package directly — everything else depends only on the core/cache.ExternalCache interface.

The two backends differ in one structurally important way: Redis supports key enumeration (DelPrefix scans and deletes matching keys), while Memcached does not (DelPrefix is a no-op there). This is safe because ObjectCache's generation-scoped keys are the real correctness guarantee — a stale entry simply expires via TTL rather than being explicitly invalidated.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type MemcachedCache

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

MemcachedCache implements core.ExternalCache backed by Memcached.

func NewMemcached

func NewMemcached(cfg MemcachedConfig) *MemcachedCache

NewMemcached constructs a MemcachedCache connected to cfg's servers.

func (*MemcachedCache) Del

func (c *MemcachedCache) Del(ctx context.Context, key string) error

func (*MemcachedCache) DelPrefix

func (c *MemcachedCache) DelPrefix(ctx context.Context, prefix string) error

DelPrefix: Memcached cannot enumerate keys, so prefix invalidation is a no-op here. Generation-scoped keys (see cache.ObjectCache) are the correctness guarantee on this backend — stale entries expire via TTL.

func (*MemcachedCache) Get

func (c *MemcachedCache) Get(ctx context.Context, key string, into any) (bool, error)

func (*MemcachedCache) Set

func (c *MemcachedCache) Set(ctx context.Context, key string, val any, ttl time.Duration) error

type MemcachedConfig

type MemcachedConfig struct {
	Servers []string // host:port
}

MemcachedConfig holds connection settings for the Memcached backend.

type RedisCache

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

RedisCache implements cache.ExternalCache backed by Redis.

func NewRedis

func NewRedis(cfg RedisConfig) *RedisCache

NewRedis constructs a RedisCache connected per cfg.

func (*RedisCache) Del

func (c *RedisCache) Del(ctx context.Context, key string) error

func (*RedisCache) DelPrefix

func (c *RedisCache) DelPrefix(ctx context.Context, prefix string) error

func (*RedisCache) Get

func (c *RedisCache) Get(ctx context.Context, key string, into any) (bool, error)

func (*RedisCache) Ping

func (c *RedisCache) Ping(ctx context.Context) error

Ping verifies connectivity; useful at startup or in health checks.

func (*RedisCache) Set

func (c *RedisCache) Set(ctx context.Context, key string, val any, ttl time.Duration) error

type RedisConfig

type RedisConfig struct {
	Addr     string
	Password string
	DB       int
}

RedisConfig holds connection settings for the Redis backend.

Jump to

Keyboard shortcuts

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