feat(cache-valkey): initial implementation — Provider, adapters (v1.0.0)

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
This commit is contained in:
2026-05-29 15:58:56 +00:00
commit df7aa63e5c
21 changed files with 2105 additions and 0 deletions

21
CHANGELOG.md Normal file
View File

@@ -0,0 +1,21 @@
# Changelog — cache-valkey
All notable changes to this module are documented here.
Format follows [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
This module adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [1.0.0] — 2026-05-28
### Added
- `Provider` interface: six common Valkey operations (`Get`, `Set`, `Del`, `Exists`,
`Expire`, `IncrWithTTL`) using only standard Go types, plus `Native() vk.Client`
escape hatch.
- `Component` interface: `Provider` + `lifecycle.Component` + `observability.Checkable`.
- `Config` struct with `EINHERJAR_VALKEY_*` env tags (caarlos0/env compatible).
- `New(logger, cfg) Component` factory — lifecycle-aware Valkey client.
- `NewPermissionCache(Provider) *PermissionCache` — satisfies `auth/rbac.Cache`
via duck typing.
- `NewRateLimiterStore(Provider, window, limit) *RateLimiterStore` — satisfies
`web/mw.RateLimiterStore` via duck typing; fixed-window Lua counter.
- `NewBlacklist(Provider) *Blacklist` — satisfies `auth-jwt.Blacklist` via duck typing.