mirror of
https://github.com/tiennm99/goclaw.git
synced 2026-07-21 06:19:18 +00:00
Add optional Redis cache support via `go build -tags redis`, following the same paired-stub pattern as OTel and Tailscale. The Cache[V] interface is unchanged; Redis and in-memory implementations are injected at startup without altering usage logic. - Add RedisCache[V] implementation with JSON serialization, fail-open on errors - Add gateway_redis.go / gateway_redis_noop.go paired wiring files - Refactor GroupWriterCache and ContextFileInterceptor to accept injected caches - Add GOCLAW_REDIS_DSN env var, docker-compose.redis.yml overlay - Update Dockerfile and GitHub Actions with ENABLE_REDIS build arg - Add Redis variant to CI matrix (5 variants: latest, otel, tsnet, redis, full)
31 lines
998 B
Go
31 lines
998 B
Go
//go:build !redis
|
|
|
|
package cmd
|
|
|
|
import (
|
|
"log/slog"
|
|
|
|
"github.com/nextlevelbuilder/goclaw/internal/cache"
|
|
"github.com/nextlevelbuilder/goclaw/internal/config"
|
|
"github.com/nextlevelbuilder/goclaw/internal/store"
|
|
)
|
|
|
|
// initRedisClient is a no-op when built without the "redis" tag.
|
|
// Build with `go build -tags redis` to enable Redis cache.
|
|
func initRedisClient(_ *config.Config) any { return nil }
|
|
|
|
// makeCaches returns in-memory cache instances when Redis is not compiled in.
|
|
func makeCaches(_ any) (
|
|
agentCtxCache cache.Cache[[]store.AgentContextFileData],
|
|
userCtxCache cache.Cache[[]store.AgentContextFileData],
|
|
groupWriterCache cache.Cache[[]store.GroupFileWriterData],
|
|
) {
|
|
slog.Info("cache backend: in-memory")
|
|
return cache.NewInMemoryCache[[]store.AgentContextFileData](),
|
|
cache.NewInMemoryCache[[]store.AgentContextFileData](),
|
|
cache.NewInMemoryCache[[]store.GroupFileWriterData]()
|
|
}
|
|
|
|
// shutdownRedis is a no-op when built without the "redis" tag.
|
|
func shutdownRedis(_ any) {}
|