Redis: Distributed Caching & Beyond
Optimize your microservice performance with blitz-fast distributed caching using Redis.
Cache Architecture
GO-DUCK implements a "Cache-Aside" strategy. This ensures that your application remains resilient: if Redis is down, the application automatically falls back to the database without crashing, thanks to our integrated Circuit Breakers (via Sony/Gobreaker).
Multi-Tenant Isolation
Standard caching in a multi-tenant app is dangerous. GO-DUCK solves this by **Tenant-Prefixing** every key automatically. Your cache keys look like tenant_abc:User:123, preventing data leaks across tenants.
Automatic Invalidation: Our repository layer handles cache invalidation. When you update or delete an entity via the REST/gRPC API, the corresponding Redis key is purged instantly to maintain data consistency.
Direct Cache Usage
import "go-duck-master-app/cache"
// Store a value for 10 minutes
cache.Set(ctx, "my-key", myStruct, 10 * time.Minute)
// Retrieve and deserialize
var target MyStruct
err := cache.Get(ctx, "my-key", &target)
Resilience with Redis
All Redis calls are wrapped in a Circuit Breaker. If Redis experiences high latency or connection resets, the circuit opens, and your Go application skips the cache layers to protect the system from cascading failure.