feat(cache,worker): overhaul cache layer and add generation task lease recovery
- shared/cache: add Options/L1/async/metrics/prefix decorators, multi-key ops, Redis pool tuning, and JSON readthrough metrics - worker-generate: claim tasks via DB lease + heartbeat, requeue stale queued tasks, expire dead leases with refund/cache invalidation - tenant: version article cache keys so worker recovery invalidations propagate cleanly - shared/config: expand Redis (pool/timeouts/TLS) and Generation (lease/recovery) configs with defaults Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
+37
@@ -41,6 +41,25 @@ func (c *memoryCache) Get(_ context.Context, key string) ([]byte, error) {
|
||||
return dst, nil
|
||||
}
|
||||
|
||||
func (c *memoryCache) GetMulti(ctx context.Context, keys []string) (map[string][]byte, error) {
|
||||
if len(keys) == 0 {
|
||||
return map[string][]byte{}, nil
|
||||
}
|
||||
|
||||
result := make(map[string][]byte, len(keys))
|
||||
for _, key := range keys {
|
||||
value, err := c.Get(ctx, key)
|
||||
if err != nil {
|
||||
if err == ErrNotFound {
|
||||
continue
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
result[key] = value
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func (c *memoryCache) Set(_ context.Context, key string, value []byte, ttl time.Duration) error {
|
||||
dst := make([]byte, len(value))
|
||||
copy(dst, value)
|
||||
@@ -51,6 +70,15 @@ func (c *memoryCache) Set(_ context.Context, key string, value []byte, ttl time.
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *memoryCache) SetMulti(ctx context.Context, items []Item) error {
|
||||
for _, item := range items {
|
||||
if err := c.Set(ctx, item.Key, item.Value, item.TTL); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *memoryCache) Delete(_ context.Context, key string) error {
|
||||
c.mu.Lock()
|
||||
delete(c.entries, key)
|
||||
@@ -58,6 +86,15 @@ func (c *memoryCache) Delete(_ context.Context, key string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *memoryCache) DeleteMany(ctx context.Context, keys []string) error {
|
||||
for _, key := range keys {
|
||||
if err := c.Delete(ctx, key); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *memoryCache) DeletePrefix(_ context.Context, prefix string) error {
|
||||
if prefix == "" {
|
||||
return nil
|
||||
|
||||
Reference in New Issue
Block a user