c1ef717d17
- 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>
41 lines
999 B
Go
41 lines
999 B
Go
package cache
|
|
|
|
import goredis "github.com/redis/go-redis/v9"
|
|
|
|
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":
|
|
backend = newRedisCache(rdb, options.DeleteScanCount)
|
|
default:
|
|
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)
|
|
}
|