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:
+31
-3
@@ -2,11 +2,39 @@ package cache
|
||||
|
||||
import goredis "github.com/redis/go-redis/v9"
|
||||
|
||||
func New(driver string, rdb *goredis.Client) Cache {
|
||||
func New(driver string, rdb *goredis.Client, opts ...Option) Cache {
|
||||
options := DefaultOptions()
|
||||
for _, opt := range opts {
|
||||
if opt != nil {
|
||||
opt(&options)
|
||||
}
|
||||
}
|
||||
return NewWithOptions(driver, rdb, options)
|
||||
}
|
||||
|
||||
func NewWithOptions(driver string, rdb *goredis.Client, options Options) Cache {
|
||||
options = normalizeOptions(options)
|
||||
|
||||
var backend Cache
|
||||
switch driver {
|
||||
case "redis":
|
||||
return newRedisCache(rdb)
|
||||
backend = newRedisCache(rdb, options.DeleteScanCount)
|
||||
default:
|
||||
return newMemoryCache()
|
||||
backend = newMemoryCache()
|
||||
}
|
||||
|
||||
if options.Namespace != "" {
|
||||
backend = newPrefixCache(backend, options.Namespace)
|
||||
}
|
||||
if options.L1Enabled && driver == "redis" {
|
||||
backend = newL1Cache(backend, options.L1TTL)
|
||||
}
|
||||
if options.MetricsEnabled {
|
||||
backend = newObservedCache(backend, driver)
|
||||
}
|
||||
if options.AsyncFillEnabled {
|
||||
backend = newAsyncCache(backend, options.AsyncFillWorkers, options.AsyncFillBuffer, options.AsyncFillTimeout)
|
||||
}
|
||||
|
||||
return newOptionsCache(backend, options)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user