Introduces code.nochebuena.dev/einherjar/cache-valkey — the Valkey cache starter for the Einherjar framework. Absorbs the valkey package from micro-lib and adds three duck-typed adapters that wire directly into auth, web, and auth-jwt. Core: - Provider interface — Get, Set, Del, Exists, Expire, IncrWithTTL, Native() - Component interface — lifecycle.Component + observability.Checkable + Provider - Config struct (EINHERJAR_VALKEY_* env vars) - New(logger, cfg) Component — creates valkey-go client in OnInit; PING in OnStart; logs "valkey: connected" - IncrWithTTL implemented with Lua script (atomic INCR + conditional EXPIRE); race-free fixed-window semantics with no MULTI/EXEC overhead - Priority: LevelDegraded — Valkey outage degrades, does not halt the service Adapters (duck-typed — no import of auth, web, or auth-jwt): - PermissionCache — Get/Set int64 bitmasks as string; satisfies auth/rbac.Cache - RateLimiterStore — fixed-window via IncrWithTTL; satisfies web/mw.RateLimiterStore - Blacklist — Exists/Set "1" with TTL; satisfies auth-jwt.Blacklist Compliance test verifies CT-6, duck-type shape assignments, and full adapter behavioural coverage with a mockProvider (no live server required). - Component interface embeds observability.Identifiable; identifiable.go implements ModulePath and ModuleVersion via runtime/debug.ReadBuildInfo() — prints in launcher banner
28 lines
1.0 KiB
Go
28 lines
1.0 KiB
Go
// Package cachevalkey provides a lifecycle-aware Valkey client with health checks
|
|
// and three adapters that integrate with other Einherjar starters via duck typing.
|
|
//
|
|
// # Quick start
|
|
//
|
|
// vk := cachevalkey.New(logger, cfg)
|
|
// launcher.Register(vk) // lifecycle: OnInit → OnStart → OnStop
|
|
// health.Register(vk) // health: PING-based, LevelDegraded
|
|
//
|
|
// # Adapters
|
|
//
|
|
// Each adapter wraps the Provider and satisfies one interface in another module.
|
|
// Go's structural typing handles the assignment — no cast required:
|
|
//
|
|
// permCache := cachevalkey.NewPermissionCache(vk) // → auth/rbac.Cache
|
|
// rateLimiter := cachevalkey.NewRateLimiterStore(vk, time.Second, 100) // → web/mw.RateLimiterStore
|
|
// blacklist := cachevalkey.NewBlacklist(vk) // → auth-jwt.Blacklist
|
|
//
|
|
// # Configuration
|
|
//
|
|
// Config fields carry caarlos0/env struct tags. Populate via environment variables
|
|
// or construct directly:
|
|
//
|
|
// cfg := cachevalkey.Config{
|
|
// Addrs: []string{"localhost:6379"},
|
|
// }
|
|
package cachevalkey
|