cache

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Jun 22, 2026 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	GatewayTTLName      = "gateway"
	RegistryTTLName     = "backend"
	ConsumerTTLName     = "consumer"
	RoleTTLName         = "role"
	ConsumerDataTTLName = "consumer_data"
	PolicyTTLName       = "policy"
	AuthTTLName         = "auth"
	AuthKeyTTLName      = "auth_key"
	LoadBalancerTTLName = "lb"
	// CatalogModelTTLName indexes catalog models by "providerCode:slug" for the
	// proxy plane's cost computation, so pricing avoids a DB round-trip on the
	// hot path after the first lookup.
	CatalogModelTTLName = "catalog_model"
	ConsumerPathTTLName = "consumer_path"
	MCPToolsTTLName     = "mcp_tools"
)
View Source
const (
	GatewayCacheTTL      = 1 * time.Hour
	RegistryCacheTTL     = 5 * time.Minute
	ConsumerCacheTTL     = 5 * time.Minute
	RoleCacheTTL         = 5 * time.Minute
	ConsumerDataCacheTTL = 1 * time.Hour
	PolicyCacheTTL       = 5 * time.Minute
	AuthCacheTTL         = 5 * time.Minute
	AuthKeyCacheTTL      = 5 * time.Minute
	LoadBalancerCacheTTL = 5 * time.Minute
	CatalogModelCacheTTL = 24 * time.Hour
	MCPToolsCacheTTL     = 5 * time.Minute
)
View Source
const (
	GatewayKeyPattern = "gateway:%s"
)

Variables

This section is empty.

Functions

func RegisterEventSubscriber

func RegisterEventSubscriber[T event.Event](pub EventListener, subscriber EventSubscriber[T])

Types

type Client

type Client interface {
	Get(ctx context.Context, key string) (string, error)
	Set(ctx context.Context, key string, value string, expiration time.Duration) error
	Delete(ctx context.Context, key string) error
	RedisClient() *redis.Client
	CreateTTLMap(name string, ttl time.Duration) *TTLMap
	GetTTLMap(name string) *TTLMap

	GetGateway(ctx context.Context, id string) (*domain.Gateway, error)
	SaveGateway(ctx context.Context, gateway *domain.Gateway) error

	DeleteAllByGatewayID(ctx context.Context, gatewayID string) error
	InvalidateAll(ctx context.Context) error
	ClearAllTTLMaps()
}

func NewClient

func NewClient(config Config, manager *TTLMapManager, logger *slog.Logger) (Client, error)

type Config

type Config struct {
	Host              string
	Port              int
	Password          string // #nosec G117 -- Config field for Redis password
	DB                int
	TLSEnabled        bool
	TLSInsecureVerify bool
}

type EventListener

type EventListener interface {
	Listen(ctx context.Context, channels ...channel.Channel)
	Register(eventType reflect.Type, subscriber interface{})
}

func NewRedisEventListener

func NewRedisEventListener(
	logger *slog.Logger,
	cache Client,
	registry map[string]reflect.Type,
) EventListener

type EventPublisher

type EventPublisher interface {
	Publish(ctx context.Context, ev event.Event) error
}

func NewRedisEventPublisher

func NewRedisEventPublisher(cache Client, channel channel.Channel) EventPublisher

type EventSubscriber

type EventSubscriber[T any] interface {
	OnEvent(ctx context.Context, ev T) error
}

type RedisIndexCreator

type RedisIndexCreator interface {
	CreateIndexes(ctx context.Context, keys ...string) error
}

func NewRedisIndexCreator

func NewRedisIndexCreator(redis *redis.Client, logger *slog.Logger) RedisIndexCreator

type RedisMessage

type RedisMessage struct {
	Type  string          `json:"type"`
	Event json.RawMessage `json:"event"`
}

type RedisPublisherInitializer

type RedisPublisherInitializer func(cache Client, channel channel.Channel) EventPublisher

type TLSClientCache

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

func NewTLSClientCache

func NewTLSClientCache(logger *slog.Logger) *TLSClientCache

func (*TLSClientCache) GetOrCreate

func (c *TLSClientCache) GetOrCreate(key string, cfg *tls.Config, proxyAddr string, proxyProtocol string) *fasthttp.Client

type TTLEntry

type TTLEntry struct {
	Value     any
	ExpiresAt time.Time
}

type TTLMap

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

func NewTTLMap

func NewTTLMap(ttl time.Duration) *TTLMap

func (*TTLMap) Clear

func (m *TTLMap) Clear()

func (*TTLMap) Delete

func (m *TTLMap) Delete(key string)

func (*TTLMap) DeleteByPrefix

func (m *TTLMap) DeleteByPrefix(prefix string)

DeleteByPrefix removes every entry whose key starts with prefix, firing onEvict for each so resource-owning values (e.g. load balancers keyed by "<gatewayID>:<consumerID>") are released. Used to evict all entries scoped to a gateway when its configuration changes.

func (*TTLMap) Get

func (m *TTLMap) Get(key string) (any, bool)

func (*TTLMap) Len

func (m *TTLMap) Len() int

func (*TTLMap) Set

func (m *TTLMap) Set(key string, value any)

func (*TTLMap) SetOnEvict

func (m *TTLMap) SetOnEvict(fn func(value any))

SetOnEvict registers a callback run with each value as it leaves the map (via Set replacement, Delete, Clear or TTL expiry), letting a namespace release resources tied to cached values. The callback runs outside the map lock.

func (*TTLMap) TTL

func (m *TTLMap) TTL() time.Duration

type TTLMapManager

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

func NewTTLMapManager

func NewTTLMapManager(defaultTTL time.Duration) *TTLMapManager

func (*TTLMapManager) ClearAllTTLMaps

func (m *TTLMapManager) ClearAllTTLMaps()

func (*TTLMapManager) CreateTTLMap

func (m *TTLMapManager) CreateTTLMap(name string, ttl time.Duration) *TTLMap

func (*TTLMapManager) DefaultTTL

func (m *TTLMapManager) DefaultTTL() time.Duration

func (*TTLMapManager) GetTTLMap

func (m *TTLMapManager) GetTTLMap(name string) *TTLMap

Directories

Path Synopsis
Package cachetest provides cache test doubles shared across app-layer tests.
Package cachetest provides cache test doubles shared across app-layer tests.
Package semantic provides a Redis Stack (RediSearch) vector store used by the semantic cache plugin to look up and persist responses by embedding similarity, scoped per rule via a hashed tag.
Package semantic provides a Redis Stack (RediSearch) vector store used by the semantic cache plugin to look up and persist responses by embedding similarity, scoped per rule via a hashed tag.

Jump to

Keyboard shortcuts

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