65 lines
2.0 KiB
Markdown
65 lines
2.0 KiB
Markdown
# 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`)
|
|
- `Cache` interface with:
|
|
- `Get(ctx context.Context, key string) ([]byte, error)`
|
|
- `Set(ctx context.Context, key string, value []byte, ttl time.Duration) error`
|
|
- `Delete(ctx context.Context, key string) error`
|
|
- `Exists(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 interface
|
|
- `internal/infra/cache/redis_cache.go` - Redis implementation
|
|
- `internal/di/providers.go` - Add cache provider
|
|
- `config/default.yaml` - Add Redis config
|
|
|