2.0 KiB
2.0 KiB
Story 5.1: Cache System (Redis)
Metadata
- Story ID: 5.1
- Title: Cache System (Redis)
- Epic: 5 - Infrastructure Adapters
- Status: Pending
- Priority: High
- Estimated Time: 4-5 hours
- Dependencies: 1.1
Goal
Implement a complete Redis-based caching system with a clean interface that can be swapped for other cache implementations.
Description
This story implements a Redis cache adapter with a clean interface, allowing modules to cache data efficiently. The cache system supports TTL, key-based operations, and optional cache middleware for HTTP responses.
Deliverables
1. Cache Interface (pkg/infra/cache/cache.go)
Cacheinterface with:Get(ctx context.Context, key string) ([]byte, error)Set(ctx context.Context, key string, value []byte, ttl time.Duration) errorDelete(ctx context.Context, key string) errorExists(ctx context.Context, key string) (bool, error)Clear(ctx context.Context) error
2. Redis Implementation (internal/infra/cache/redis_cache.go)
- Redis client setup
- Connection pooling
- All interface methods implemented
- Error handling
- Connection health checks
3. Configuration
- Redis config in
config/default.yaml:- Connection URL
- Pool settings
- Default TTL
4. DI Integration
- Provider function for Cache
- Register in DI container
5. Optional Cache Middleware
- HTTP response caching middleware
- Configurable cache keys
- TTL per route
Acceptance Criteria
- Cache interface is defined
- Redis implementation works correctly
- Cache operations (get, set, delete) work
- TTL is respected
- Cache is injectable via DI
- Configuration is loaded from config
- Optional middleware works
Files to Create/Modify
pkg/infra/cache/cache.go- Cache interfaceinternal/infra/cache/redis_cache.go- Redis implementationinternal/di/providers.go- Add cache providerconfig/default.yaml- Add Redis config