From 5c64e18f28b12d7100e7d411d94947b55d342af8 Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 28 Oct 2026 02:06:42 +0000 Subject: [PATCH 1/5] cache: harden cacheaside timeouts and flight key, validate SetNX ttl - Give in-load cache read/write their own 1s timeout so a slow cache cannot consume LoadTimeout. - Scope singleflight key by Cache instance so identical keys on different caches load separately. - Treat negative TTL as no expiry; reject SetNX ttl <= 0 with ErrInvalidTTL. - Document Load must not panic, nil-sentinel collision, stale-write race. Co-Authored-By: Claude Sonnet 5.5 Claude-Session: https://claude.ai/code/session_01PPH4seaqkaPedocjzkHZ4L --- cache/README.md | 12 ++++- cache/cacheaside/cacheaside.go | 46 ++++++++++++----- cache/cacheaside/cacheaside_test.go | 78 +++++++++++++++++++++++++++++ cache/client.go | 6 +++ cache/redis_cache.go | 4 ++ cache/redis_cache_test.go | 9 ++++ 6 files changed, 140 insertions(+), 15 deletions(-) diff --git a/cache/README.md b/cache/README.md index 56e631d..751e711 100644 --- a/cache/README.md +++ b/cache/README.md @@ -86,6 +86,7 @@ type Cache interface { - `NewRedisCacheFromConfig(RedisConfig)` builds a `Cache` with auth, TLS, DB, pool, and timeout settings. It does not connect; a failure shows on the first operation. `NewRedisCache(addr)` is the no-auth shortcut. - `Get` returns `ErrCacheMiss` for a missing key. Check it with `cache.IsCacheMiss(err)`. - `SetNX` and `DelIfValue` are low-level primitives. `cacheaside.GetOrSet` does not use them. +- `SetNX` requires a positive TTL and returns `ErrInvalidTTL` otherwise, because a lock without an expiry is never released if its holder crashes. ## Cache-aside (`cache/cacheaside`) @@ -95,11 +96,18 @@ type Cache interface { |---|---| | Stampede control | Concurrent misses for one key share one `Load` per process. Not coordinated across instances. | | TTL jitter | Stored TTL varies by ±10%, so keys do not expire together. | -| `LoadTimeout` | Bounds one `Load` (default 5s). Callers waiting on the same key share this budget. | +| `LoadTimeout` | Bounds one `Load` (default 5s). Callers waiting on the same key share this budget. The cache read and write around `Load` have their own 1s limit each. | | Degradation | A failed read counts as a miss. A failed write still returns the value. Both are reported to `OnError`. | | `CacheNil` | Optionally stores empty results so known-missing keys are not reloaded. | -Each `GetOrSet` call takes a `cacheaside.GetOrSetRequest`. Keys must be unique per source: concurrent loads share one singleflight group across every `Cache` in the process. +Each `GetOrSet` call takes a `cacheaside.GetOrSetRequest`. Concurrent loads are shared per `Cache` instance and key, so the same key on two caches loads separately. Keys must still be unique per source within one cache. + +Caveats: + +- `Load` must return failures as errors and must not panic. A panic in `Load` cannot be recovered by the caller and ends the process. +- A `Load` result equal to the internal nil sentinel (`"\x00nil\x00"`) reads back as an empty string. +- A `Del` that lands while a `Load` is in flight can be overwritten by that load's stale result, which then stays cached for a full TTL. +- A zero or negative `TTL` stores the value without expiry. ## Package layout diff --git a/cache/cacheaside/cacheaside.go b/cache/cacheaside/cacheaside.go index ff3df66..711bafd 100644 --- a/cache/cacheaside/cacheaside.go +++ b/cache/cacheaside/cacheaside.go @@ -5,6 +5,7 @@ package cacheaside import ( "context" + "fmt" "math/rand/v2" "time" @@ -15,17 +16,25 @@ import ( const ( defaultLoadTimeout = 5 * time.Second - nilSentinel = "\x00nil\x00" + // cacheOpTimeout bounds each cache read or write made inside a load, so a + // slow cache cannot use up the time LoadTimeout gives the loader. + cacheOpTimeout = time.Second + nilSentinel = "\x00nil\x00" // jitterFraction spreads expiry by up to ±10% so keys stored together do // not expire together. jitterFraction = 0.1 ) // loads coalesces concurrent loads for the same key within this process. It is -// shared by every Cache in the process, so the same key on two Caches (for -// example two Redis databases) shares one load. +// keyed by Cache instance and key, so the same key on two Caches (for example +// two Redis databases) loads separately. var loads singleflight.Group +// flightKey scopes key to the Cache it is stored in. +func flightKey(c cache.Cache, key string) string { + return fmt.Sprintf("%p\x00%s", c, key) +} + // GetOrSetOptions tunes one GetOrSet call. Zero values select the defaults. type GetOrSetOptions struct { // LoadTimeout bounds one run of Load. Concurrent callers for the key wait for @@ -45,11 +54,14 @@ type GetOrSetOptions struct { type GetOrSetRequest struct { // Cache is the store to read from and write to. Cache cache.Cache - // Key is the cache key. Load runs once per key within the process. + // Key is the cache key. Load runs once per Cache and key within the process. Key string - // TTL is the stored lifetime, varied by ±10%. Zero means no expiry. + // TTL is the stored lifetime, varied by ±10%. Zero or negative means no expiry. TTL time.Duration - // Load computes the value on a miss. + // Load computes the value on a miss. It must report failures by returning an + // error, never by panicking: a panic in Load cannot be recovered by the + // caller and ends the process. A result equal to the internal nil sentinel + // ("\x00nil\x00") reads back as an empty string. Load func(context.Context) (string, error) // Options tunes the call. Zero values select the defaults. Options GetOrSetOptions @@ -74,11 +86,11 @@ func GetOrSet(ctx context.Context, req GetOrSetRequest) (string, error) { } req.Options = withDefaults(req.Options) - if val, ok := lookup(ctx, req.Cache, req.Key, req.Options); ok { + if val, ok := lookup(ctx, ctx, req.Cache, req.Key, req.Options); ok { return val, nil } - ch := loads.DoChan(req.Key, func() (any, error) { + ch := loads.DoChan(flightKey(req.Cache, req.Key), func() (any, error) { return load(ctx, req) }) // The caller stops waiting when its ctx ends. The load keeps running for @@ -103,7 +115,10 @@ func load(ctx context.Context, req GetOrSetRequest) (string, error) { defer cancel() // Another process may have stored the key since our first read. - if val, ok := lookup(ctx, req.Cache, req.Key, req.Options); ok { + readCtx, cancelRead := context.WithTimeout(ctx, cacheOpTimeout) + val, ok := lookup(ctx, readCtx, req.Cache, req.Key, req.Options) + cancelRead() + if ok { return val, nil } @@ -120,7 +135,10 @@ func load(ctx context.Context, req GetOrSetRequest) (string, error) { } storeVal = nilSentinel } - if err := req.Cache.Set(ctx, req.Key, storeVal, jitter(req.TTL)); err != nil { + // Set gets its own budget: Load may have used all of ctx. + writeCtx, cancelWrite := context.WithTimeout(context.WithoutCancel(ctx), cacheOpTimeout) + defer cancelWrite() + if err := req.Cache.Set(writeCtx, req.Key, storeVal, jitter(max(req.TTL, 0))); err != nil { // The value is still good. The next call will load it again. req.Options.report(err) } @@ -129,9 +147,11 @@ func load(ctx context.Context, req GetOrSetRequest) (string, error) { // lookup returns the cached value and whether it was found. A read error other // than a miss is reported and treated as a miss. Once ctx has ended, the error -// is a result of the caller leaving, so it is not reported. -func lookup(ctx context.Context, c cache.Cache, key string, o GetOrSetOptions) (string, bool) { - val, err := c.Get(ctx, key) +// is a result of the caller leaving, so it is not reported. The read itself +// runs under readCtx, which may be a shorter-lived child of ctx: its timeout is +// a cache failure and is reported. +func lookup(ctx, readCtx context.Context, c cache.Cache, key string, o GetOrSetOptions) (string, bool) { + val, err := c.Get(readCtx, key) if err == nil { return fromStore(val), true } diff --git a/cache/cacheaside/cacheaside_test.go b/cache/cacheaside/cacheaside_test.go index 59d0d49..532a900 100644 --- a/cache/cacheaside/cacheaside_test.go +++ b/cache/cacheaside/cacheaside_test.go @@ -326,3 +326,81 @@ func TestRedisCache_GetOrSet_CustomLoadTimeout(t *testing.T) { assert.NoError(t, err) assert.Equal(t, "custom-timeout", val) } + +// hangingReadCache misses on the first Get, then blocks every later Get until +// its ctx ends, like a cache that stops answering mid-request. +type hangingReadCache struct { + cache.Cache + gets atomic.Int32 +} + +func (h *hangingReadCache) Get(ctx context.Context, _ string) (string, error) { + if h.gets.Add(1) == 1 { + return "", cache.ErrCacheMiss + } + <-ctx.Done() + return "", ctx.Err() +} + +func TestGetOrSet_SlowCacheDoesNotStarveLoader(t *testing.T) { + mr, c := setupTestRedis(t) + defer mr.Close() + + var remaining time.Duration + var reported atomic.Int32 + val, err := GetOrSet(context.Background(), GetOrSetRequest{Cache: &hangingReadCache{Cache: c}, Key: "slow-cache", TTL: time.Minute, + Load: func(ctx context.Context) (string, error) { + dl, _ := ctx.Deadline() + remaining = time.Until(dl) + return "v", nil + }, + Options: GetOrSetOptions{LoadTimeout: 5 * time.Second, OnError: func(error) { reported.Add(1) }}}) + require.NoError(t, err) + assert.Equal(t, "v", val) + // The hung read costs cacheOpTimeout, not the loader's whole budget. + assert.Greater(t, remaining, 3*time.Second) + assert.Equal(t, int32(1), reported.Load(), "the read timeout must reach OnError") +} + +func TestGetOrSet_SameKeyOnDifferentCachesLoadsSeparately(t *testing.T) { + mr1, c1 := setupTestRedis(t) + defer mr1.Close() + mr2, c2 := setupTestRedis(t) + defer mr2.Close() + + ctx := context.Background() + var calls atomic.Int32 + load := func(v string) func(context.Context) (string, error) { + return func(context.Context) (string, error) { + calls.Add(1) + time.Sleep(100 * time.Millisecond) + return v, nil + } + } + + var wg sync.WaitGroup + var v1, v2 string + wg.Go(func() { + v1, _ = GetOrSet(ctx, GetOrSetRequest{Cache: c1, Key: "same", TTL: time.Minute, Load: load("one")}) + }) + wg.Go(func() { + v2, _ = GetOrSet(ctx, GetOrSetRequest{Cache: c2, Key: "same", TTL: time.Minute, Load: load("two")}) + }) + wg.Wait() + + assert.Equal(t, "one", v1) + assert.Equal(t, "two", v2) + assert.Equal(t, int32(2), calls.Load()) +} + +func TestGetOrSet_NegativeTTLMeansNoExpiry(t *testing.T) { + mr, c := setupTestRedis(t) + defer mr.Close() + + _, err := GetOrSet(context.Background(), GetOrSetRequest{Cache: c, Key: "neg-ttl", TTL: -time.Second, Load: func(context.Context) (string, error) { + return "v", nil + }}) + require.NoError(t, err) + assert.True(t, mr.Exists("neg-ttl")) + assert.Zero(t, mr.TTL("neg-ttl"), "negative ttl must store without expiry") +} diff --git a/cache/client.go b/cache/client.go index 1b54f0f..b6f1de4 100644 --- a/cache/client.go +++ b/cache/client.go @@ -11,6 +11,10 @@ import ( // ErrCacheMiss is returned by Cache.Get when the key does not exist. var ErrCacheMiss = errors.New("cache miss") +// ErrInvalidTTL is returned by Cache.SetNX when ttl is not positive. A lock +// without an expiry is never released if its holder crashes. +var ErrInvalidTTL = errors.New("ttl must be positive") + // IsCacheMiss reports whether err represents a cache miss. // Use it instead of comparing errors to a backend's nil sentinel. func IsCacheMiss(err error) bool { @@ -21,6 +25,8 @@ func IsCacheMiss(err error) bool { // NewRedisCacheFromConfig. cacheaside works with any implementation. type Cache interface { Set(ctx context.Context, key string, value string, ttl time.Duration) error + // SetNX stores value only if key is absent and reports whether it did. ttl + // must be positive, otherwise it returns ErrInvalidTTL. SetNX(ctx context.Context, key string, value string, ttl time.Duration) (bool, error) Get(ctx context.Context, key string) (string, error) Del(ctx context.Context, key string) error diff --git a/cache/redis_cache.go b/cache/redis_cache.go index 2554c83..cb977b7 100644 --- a/cache/redis_cache.go +++ b/cache/redis_cache.go @@ -100,7 +100,11 @@ func (r *redisCache) DelIfValue(ctx context.Context, key, value string) (bool, e // SetNX atomically sets key only if it does not exist and reports whether it // did. For a lock, store a random token as the value and release it with // DelIfValue, not Del. The TTL is not extended and the lock is not reentrant. +// ttl must be positive, otherwise it returns ErrInvalidTTL. func (r *redisCache) SetNX(ctx context.Context, key, value string, ttl time.Duration) (bool, error) { + if ttl <= 0 { + return false, ErrInvalidTTL + } return r.client.SetNX(ctx, key, value, ttl).Result() } diff --git a/cache/redis_cache_test.go b/cache/redis_cache_test.go index 2c8f46f..47add5d 100644 --- a/cache/redis_cache_test.go +++ b/cache/redis_cache_test.go @@ -196,6 +196,15 @@ func TestRedisCache_SetNX(t *testing.T) { assert.False(t, exists) }) + t.Run("setnx rejects non-positive ttl", func(t *testing.T) { + for _, ttl := range []time.Duration{0, -time.Second} { + ok, err := cache.SetNX(ctx, "setnx-bad-ttl", "v", ttl) + assert.ErrorIs(t, err, ErrInvalidTTL) + assert.False(t, ok) + } + assert.False(t, mr.Exists("setnx-bad-ttl")) + }) + t.Run("setnx after key expires", func(t *testing.T) { ok, err := cache.SetNX(ctx, "expire-then-setnx", "first-value", 1*time.Second) assert.NoError(t, err) From affbc68c7fdb1c6e464405daf0bf3e68499e5c0a Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 28 Oct 2026 02:40:06 +0000 Subject: [PATCH 2/5] cache: fix outdated docs and trim README duplication - Diagram: per-cache flight key, separate 1s cache timeouts, panic row, drop blog front matter and stale 'was removed' wording. - README: drop the copied interface block and layout table, link to the diagram doc instead of repeating it, use log.Fatal in the example. Co-Authored-By: Claude Sonnet 5.5 Claude-Session: https://claude.ai/code/session_01PPH4seaqkaPedocjzkHZ4L --- cache/README.md | 69 +++++++---------------------------- cache/diagrams/cache_aside.md | 20 +++------- 2 files changed, 20 insertions(+), 69 deletions(-) diff --git a/cache/README.md b/cache/README.md index 751e711..060094e 100644 --- a/cache/README.md +++ b/cache/README.md @@ -2,7 +2,7 @@ [![Go Reference](https://pkg.go.dev/badge/github.com/Chandra179/fiddle/cache.svg)](https://pkg.go.dev/github.com/Chandra179/fiddle/cache) -A small key-value `Cache` interface with a cache-aside helper. Redis is the bundled implementation. Minimal surface, battle-tested patterns. +A small key-value `Cache` interface with a cache-aside helper. Redis is the bundled implementation. Minimal surface. ## Install @@ -20,6 +20,7 @@ package main import ( "context" "fmt" + "log" "time" "github.com/Chandra179/fiddle/cache" @@ -35,7 +36,7 @@ func main() { }) defer c.Close() - // Read-through: returns the cached value, or runs Load and stores the result. + // Returns the cached value, or runs Load and stores the result. user, err := cacheaside.GetOrSet(ctx, cacheaside.GetOrSetRequest{ Cache: c, Key: "user:42", @@ -45,80 +46,38 @@ func main() { }, Options: cacheaside.GetOrSetOptions{ LoadTimeout: 2 * time.Second, - OnError: func(err error) { fmt.Println("cache error:", err) }, + OnError: func(err error) { log.Println("cache error:", err) }, }, }) if err != nil { - panic(err) + log.Fatal(err) } fmt.Println(user) - - // Direct use of the Cache interface. - if err := c.Set(ctx, "greeting", "hello", time.Minute); err != nil { - panic(err) - } - v, err := c.Get(ctx, "greeting") - if cache.IsCacheMiss(err) { - fmt.Println("not cached") - } else if err != nil { - panic(err) - } else { - fmt.Println(v) - } } ``` -## Current API +## API -```go -type Cache interface { - Set(ctx context.Context, key string, value string, ttl time.Duration) error - SetNX(ctx context.Context, key string, value string, ttl time.Duration) (bool, error) - Get(ctx context.Context, key string) (string, error) - Del(ctx context.Context, key string) error - DelIfValue(ctx context.Context, key, value string) (bool, error) - Ping(ctx context.Context) error - Close() error -} -``` +The `Cache` interface (see [pkg.go.dev](https://pkg.go.dev/github.com/Chandra179/fiddle/cache) for signatures): -- `Cache` is backend-neutral. `cacheaside` works with any implementation; `redis_cache.go` provides one backed by Redis. -- `NewRedisCacheFromConfig(RedisConfig)` builds a `Cache` with auth, TLS, DB, pool, and timeout settings. It does not connect; a failure shows on the first operation. `NewRedisCache(addr)` is the no-auth shortcut. -- `Get` returns `ErrCacheMiss` for a missing key. Check it with `cache.IsCacheMiss(err)`. -- `SetNX` and `DelIfValue` are low-level primitives. `cacheaside.GetOrSet` does not use them. -- `SetNX` requires a positive TTL and returns `ErrInvalidTTL` otherwise, because a lock without an expiry is never released if its holder crashes. +- `Set`, `Get`, `Del`: basic key-value access. `Get` returns `ErrCacheMiss` for a missing key; test it with `cache.IsCacheMiss(err)`. +- `SetNX`, `DelIfValue`: lock primitives. `SetNX` requires a positive TTL and returns `ErrInvalidTTL` otherwise. `cacheaside.GetOrSet` does not use them. +- `Ping`, `Close`. -## Cache-aside (`cache/cacheaside`) - -`cacheaside.GetOrSet` is the read path of the cache-aside pattern. A call checks the cache, runs `Load` on a miss, and stores the result. Writes and invalidation stay with the caller. See [diagrams/cache_aside.md](diagrams/cache_aside.md) for the read path, failure behavior, and use cases. +`NewRedisCacheFromConfig(RedisConfig)` builds a Redis-backed `Cache` with auth, TLS, DB, pool and timeout settings. It does not connect; a failure shows on the first operation. `NewRedisCache(addr)` is the no-auth shortcut. -| Behavior | Details | -|---|---| -| Stampede control | Concurrent misses for one key share one `Load` per process. Not coordinated across instances. | -| TTL jitter | Stored TTL varies by ±10%, so keys do not expire together. | -| `LoadTimeout` | Bounds one `Load` (default 5s). Callers waiting on the same key share this budget. The cache read and write around `Load` have their own 1s limit each. | -| Degradation | A failed read counts as a miss. A failed write still returns the value. Both are reported to `OnError`. | -| `CacheNil` | Optionally stores empty results so known-missing keys are not reloaded. | +## Cache-aside (`cache/cacheaside`) -Each `GetOrSet` call takes a `cacheaside.GetOrSetRequest`. Concurrent loads are shared per `Cache` instance and key, so the same key on two caches loads separately. Keys must still be unique per source within one cache. +`cacheaside.GetOrSet` is the read path of the cache-aside pattern: check the cache, run `Load` on a miss, store the result. Concurrent misses for a key share one `Load` per process, stored TTLs vary by ±10%, and cache failures degrade to the loader instead of failing the call. Writes and invalidation stay with the caller. See [diagrams/cache_aside.md](diagrams/cache_aside.md) for the read path, failure behavior, options and use cases. Caveats: - `Load` must return failures as errors and must not panic. A panic in `Load` cannot be recovered by the caller and ends the process. +- Stampede control covers one process and one `Cache` instance; instances that miss together each run `Load`. - A `Load` result equal to the internal nil sentinel (`"\x00nil\x00"`) reads back as an empty string. - A `Del` that lands while a `Load` is in flight can be overwritten by that load's stale result, which then stays cached for a full TTL. - A zero or negative `TTL` stores the value without expiry. -## Package layout - -| Path | Contents | -|---|---| -| `client.go` | `Cache` interface, `ErrCacheMiss`, `IsCacheMiss` | -| `redis_cache.go` | Redis implementation and constructors | -| `cacheaside/` | `GetOrSet` and its request and option types | -| `example/` | Integration tests (Docker required, build tag `integration`) | -| `diagrams/` | Design notes | - ## Testing ```bash diff --git a/cache/diagrams/cache_aside.md b/cache/diagrams/cache_aside.md index e808a43..f3ae8d7 100644 --- a/cache/diagrams/cache_aside.md +++ b/cache/diagrams/cache_aside.md @@ -1,13 +1,3 @@ ---- -title: "Cache Aside" -created: 2026-10-27 -tags: [cache, architecture, redis, software-design, golang] -description: "How the cache-aside pattern works and how cacheaside.GetOrSet implements its read path in Go." -seoTitle: "Cache Aside Pattern in Go" -seoDescription: "Cache-aside pattern in Go: read path, stampede protection, failure handling, and when to use it with Redis." -answerSummary: "Cache aside is a read pattern: the application checks the cache first, loads from the source on a miss, and stores the result. cacheaside.GetOrSet implements this read path with per-process stampede protection and graceful degradation when Redis fails. Writes and invalidation remain the caller's responsibility." ---- - # Cache-aside ## Big picture @@ -39,7 +29,7 @@ change the source. | miss, or Redis read error (counted as a miss) v +------------------------------+ -| singleflight(key) | first caller starts the load; +| singleflight(cache, key) | first caller starts the load; | | other callers in this process wait +------------------------------+ | @@ -47,7 +37,7 @@ change the source. v +------------------------------+ | 2. Get(key) again |---- hit -----------------> return value -+------------------------------+ ++------------------------------+ own 1s limit, apart from LoadTimeout | | miss v @@ -59,7 +49,7 @@ change the source. | ok error ---> returned to every waiting caller, v nothing cached +------------------------------+ -| 4. Set(key, value, TTL) | TTL varied by +/- 10% +| 4. Set(key, value, TTL) | TTL varied by +/- 10%, own 1s limit +------------------------------+ write error ---> OnError, value still returned | v @@ -71,8 +61,10 @@ change the source. | Event | Result | |---|---| | Redis read fails | Treated as a miss. Load runs. `OnError` is called. | +| Redis hangs | The read inside the load waits at most 1s, then counts as a miss. `Load` keeps its full `LoadTimeout`. | | Redis write fails | Value is still returned. `OnError` is called. Next call loads again. | | `Load` returns an error | Every waiting caller gets it. Nothing is cached. | +| `Load` panics | Not recovered: the process ends. `Load` must return errors instead. | | `Load` runs past `LoadTimeout` | Its `ctx` is cancelled. If `Load` honors it, every waiting caller gets `DeadlineExceeded`. | | A caller's `ctx` ends | That caller returns `ctx.Err()`. The load keeps running for the others. | | Two instances miss at once | Each runs `Load` once. Cross-instance dedup is not provided. | @@ -107,4 +99,4 @@ staleness is acceptable, and the same key is requested in bursts. - Loaders under a few milliseconds. The cache round trip costs as much as the load. - Reads that must be current after every write (use invalidation or no cache). - Large fleets with expensive loaders where cross-instance duplicate loads are - measured. That needs a distributed lock, which was removed. + measured. That needs a distributed lock, which this package does not provide. From 47451aaffd38e7286f8e4b177e4e39d40e14af17 Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 28 Oct 2026 04:00:12 +0000 Subject: [PATCH 3/5] cache: restore cache_aside.md front matter used by the published copy The previous commit removed it on the assumption nothing used it. Restore it, including links.github, and bump updated. Co-Authored-By: Claude Sonnet 5.5 Claude-Session: https://claude.ai/code/session_01PPH4seaqkaPedocjzkHZ4L --- cache/diagrams/cache_aside.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/cache/diagrams/cache_aside.md b/cache/diagrams/cache_aside.md index f3ae8d7..c71b99d 100644 --- a/cache/diagrams/cache_aside.md +++ b/cache/diagrams/cache_aside.md @@ -1,3 +1,16 @@ +--- +title: "Cache Aside" +created: 2026-10-27 +tags: [cache, architecture, redis, software-design, golang] +description: "How the cache-aside pattern works and how cacheaside.GetOrSet implements its read path in Go." +seoTitle: "Cache Aside Pattern in Go" +seoDescription: "Cache-aside pattern in Go: read path, stampede protection, failure handling, and when to use it with Redis." +answerSummary: "Cache aside is a read pattern: the application checks the cache first, loads from the source on a miss, and stores the result. cacheaside.GetOrSet implements this read path with per-process stampede protection and graceful degradation when Redis fails. Writes and invalidation remain the caller's responsibility." +links: + github: "https://github.com/Chandra179/fiddle/blob/main/cache/cacheaside/cacheaside.go" +updated: 2026-10-28 +--- + # Cache-aside ## Big picture From c213be8389e03f90b82934814494a2460758171f Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 28 Oct 2026 06:01:56 +0000 Subject: [PATCH 4/5] cache: bound first read, enable ctx deadlines in go-redis, harden flight key - Apply cacheOpTimeout to the first lookup too. - Set ContextTimeoutEnabled so go-redis honours ctx deadlines; without it the 1s cache limits did nothing against a hung Redis (9s measured, 3s now). - flightKey: only scope by pointer Caches; fall back to the key otherwise. - jitter returns 0 for non-positive ttl instead of the caller clamping. Co-Authored-By: Claude Sonnet 5.5 Claude-Session: https://claude.ai/code/session_01PPH4seaqkaPedocjzkHZ4L --- cache/cacheaside/cacheaside.go | 36 +++++++++++++++++++---------- cache/cacheaside/cacheaside_test.go | 16 ++++++++++++- cache/redis_cache.go | 3 +++ 3 files changed, 42 insertions(+), 13 deletions(-) diff --git a/cache/cacheaside/cacheaside.go b/cache/cacheaside/cacheaside.go index 711bafd..28f6449 100644 --- a/cache/cacheaside/cacheaside.go +++ b/cache/cacheaside/cacheaside.go @@ -7,6 +7,7 @@ import ( "context" "fmt" "math/rand/v2" + "reflect" "time" "github.com/Chandra179/fiddle/cache" @@ -30,16 +31,22 @@ const ( // two Redis databases) loads separately. var loads singleflight.Group -// flightKey scopes key to the Cache it is stored in. +// flightKey scopes key to the Cache it is stored in. Scoping needs a pointer +// Cache, which every constructor here returns; any other Cache shares loads by +// key alone. func flightKey(c cache.Cache, key string) string { - return fmt.Sprintf("%p\x00%s", c, key) + if v := reflect.ValueOf(c); v.Kind() == reflect.Pointer { + return fmt.Sprintf("%x\x00%s", v.Pointer(), key) + } + return key } // GetOrSetOptions tunes one GetOrSet call. Zero values select the defaults. type GetOrSetOptions struct { // LoadTimeout bounds one run of Load. Concurrent callers for the key wait for // that run, so it also bounds their wait. Set it above the loader's p99 - // latency. Defaults to 5s. + // latency. Defaults to 5s. The cache read before and the write after Load + // have their own 1s limit each, so a caller can wait slightly longer. LoadTimeout time.Duration // CacheNil stores an empty result as a sentinel, so a known-missing key is // not reloaded on every call. @@ -86,7 +93,7 @@ func GetOrSet(ctx context.Context, req GetOrSetRequest) (string, error) { } req.Options = withDefaults(req.Options) - if val, ok := lookup(ctx, ctx, req.Cache, req.Key, req.Options); ok { + if val, ok := boundedLookup(ctx, req); ok { return val, nil } @@ -115,10 +122,7 @@ func load(ctx context.Context, req GetOrSetRequest) (string, error) { defer cancel() // Another process may have stored the key since our first read. - readCtx, cancelRead := context.WithTimeout(ctx, cacheOpTimeout) - val, ok := lookup(ctx, readCtx, req.Cache, req.Key, req.Options) - cancelRead() - if ok { + if val, ok := boundedLookup(ctx, req); ok { return val, nil } @@ -138,13 +142,21 @@ func load(ctx context.Context, req GetOrSetRequest) (string, error) { // Set gets its own budget: Load may have used all of ctx. writeCtx, cancelWrite := context.WithTimeout(context.WithoutCancel(ctx), cacheOpTimeout) defer cancelWrite() - if err := req.Cache.Set(writeCtx, req.Key, storeVal, jitter(max(req.TTL, 0))); err != nil { + if err := req.Cache.Set(writeCtx, req.Key, storeVal, jitter(req.TTL)); err != nil { // The value is still good. The next call will load it again. req.Options.report(err) } return result, nil } +// boundedLookup is lookup limited to cacheOpTimeout, so a hung cache costs one +// short wait instead of the caller's whole deadline. +func boundedLookup(ctx context.Context, req GetOrSetRequest) (string, bool) { + readCtx, cancel := context.WithTimeout(ctx, cacheOpTimeout) + defer cancel() + return lookup(ctx, readCtx, req.Cache, req.Key, req.Options) +} + // lookup returns the cached value and whether it was found. A read error other // than a miss is reported and treated as a miss. Once ctx has ended, the error // is a result of the caller leaving, so it is not reported. The read itself @@ -167,11 +179,11 @@ func (o GetOrSetOptions) report(err error) { } } -// jitter returns ttl changed by up to ±jitterFraction. A non-positive ttl (no -// expiry) is returned unchanged. +// jitter returns ttl changed by up to ±jitterFraction. A non-positive ttl means +// no expiry and returns 0. func jitter(ttl time.Duration) time.Duration { if ttl <= 0 { - return ttl + return 0 } spread := float64(ttl) * jitterFraction d := ttl + time.Duration((rand.Float64()*2-1)*spread) diff --git a/cache/cacheaside/cacheaside_test.go b/cache/cacheaside/cacheaside_test.go index 532a900..b47a7c8 100644 --- a/cache/cacheaside/cacheaside_test.go +++ b/cache/cacheaside/cacheaside_test.go @@ -186,7 +186,7 @@ func TestGetOrSet_StoresJitteredTTL(t *testing.T) { func TestJitter(t *testing.T) { assert.Equal(t, time.Duration(0), jitter(0), "no expiry stays no expiry") - assert.Equal(t, -time.Second, jitter(-time.Second), "negative ttl is unchanged") + assert.Equal(t, time.Duration(0), jitter(-time.Second), "negative ttl means no expiry") base := time.Minute seen := map[time.Duration]bool{} @@ -404,3 +404,17 @@ func TestGetOrSet_NegativeTTLMeansNoExpiry(t *testing.T) { assert.True(t, mr.Exists("neg-ttl")) assert.Zero(t, mr.TTL("neg-ttl"), "negative ttl must store without expiry") } + +// valueCache is a non-pointer Cache, which flightKey cannot tell apart. +type valueCache struct{ cache.Cache } + +func TestFlightKey(t *testing.T) { + mr, c := setupTestRedis(t) + defer mr.Close() + mr2, c2 := setupTestRedis(t) + defer mr2.Close() + + assert.NotEqual(t, flightKey(c, "k"), flightKey(c2, "k"), "distinct pointer caches get distinct keys") + assert.Equal(t, flightKey(c, "k"), flightKey(c, "k")) + assert.Equal(t, "k", flightKey(valueCache{c}, "k"), "non-pointer cache falls back to the bare key") +} diff --git a/cache/redis_cache.go b/cache/redis_cache.go index cb977b7..a1836e2 100644 --- a/cache/redis_cache.go +++ b/cache/redis_cache.go @@ -46,6 +46,9 @@ func NewRedisCacheFromConfig(cfg RedisConfig) Cache { ReadTimeout: cfg.ReadTimeout, WriteTimeout: cfg.WriteTimeout, PoolSize: cfg.PoolSize, + // Without this go-redis ignores ctx deadlines on network I/O, so the + // timeouts cacheaside sets would not apply. + ContextTimeoutEnabled: true, }) return &redisCache{client: rdb} } From 63ede337fa8cbb04b87a12c8f120e6a1358f2c8f Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 28 Oct 2026 12:17:36 +0000 Subject: [PATCH 5/5] cache: remove the testcontainers integration tests The unit tests (miniredis) cover the same behaviour without Docker. Drop cache/example, the testcontainers dependency, the cache entry in the CI integration matrix and the Docker wording in the Makefile and docs. Co-Authored-By: Claude Sonnet 5.5 Claude-Session: https://claude.ai/code/session_01PPH4seaqkaPedocjzkHZ4L --- .github/workflows/ci.yml | 4 +- AGENTS.md | 2 +- cache/Makefile | 8 +- cache/README.md | 3 +- cache/example/redis_integration_test.go | 415 ------------------------ cache/go.mod | 48 --- cache/go.sum | 123 ------- 7 files changed, 6 insertions(+), 597 deletions(-) delete mode 100644 cache/example/redis_integration_test.go diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c9f6f22..cd42848 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -46,7 +46,7 @@ jobs: - name: govulncheck run: make vuln - # Integration tests. db, cache, kafka and rabbitmq start their dependencies + # Integration tests. db, kafka and rabbitmq start their dependencies # with testcontainers (Docker is available on ubuntu-latest); oauth2 and i18n # use in-process fakes. integration: @@ -55,7 +55,7 @@ jobs: strategy: fail-fast: false matrix: - module: [db, cache, kafka, rabbitmq, oauth2, i18n] + module: [db, kafka, rabbitmq, oauth2, i18n] defaults: run: working-directory: ${{ matrix.module }} diff --git a/AGENTS.md b/AGENTS.md index 31423d9..d3cfaf3 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -7,7 +7,7 @@ Multi-module Go monorepo. Each subdirectory is its own Go module. | Module | Module path (go.mod) | Has Makefile | Docker needed for tests | |--------|---------------------|--------------|------------------------| | db/ | `db` | yes | yes (testcontainers) | -| cache/ | `cache` | yes | no* — unit tests use miniredis | +| cache/ | `cache` | yes | no — unit tests use miniredis | | kafka/ | `kafka` | yes | yes (testcontainers) | | rabbitmq/ | `rabbitmq` | yes | yes (testcontainers) | | oauth2/ | `oauth2` | yes | no* — mock OIDC server | diff --git a/cache/Makefile b/cache/Makefile index 1dbe7f1..880de94 100644 --- a/cache/Makefile +++ b/cache/Makefile @@ -2,10 +2,6 @@ include ../Makefile.common -# Everything, including the integration tests (needs Docker: testcontainers). -test: - go test -tags integration -v -count=1 -timeout 300s ./... - -# Unit tests only: no Docker, the integration tests are excluded by build tag. -test-unit: +# All tests are unit tests on miniredis: no Docker needed. +test test-unit: go test -count=1 -timeout 120s ./... diff --git a/cache/README.md b/cache/README.md index 060094e..1450a47 100644 --- a/cache/README.md +++ b/cache/README.md @@ -81,8 +81,7 @@ Caveats: ## Testing ```bash -make test-unit # unit tests, miniredis, no Docker -make test # all tests, integration needs Docker +make test # unit tests on miniredis, no Docker needed ``` ## License diff --git a/cache/example/redis_integration_test.go b/cache/example/redis_integration_test.go deleted file mode 100644 index fd2d06e..0000000 --- a/cache/example/redis_integration_test.go +++ /dev/null @@ -1,415 +0,0 @@ -//go:build integration - -package example - -import ( - "context" - "log" - "os" - "sync" - "sync/atomic" - "testing" - "time" - - "github.com/Chandra179/fiddle/cache" - "github.com/Chandra179/fiddle/cache/cacheaside" - - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" - "github.com/testcontainers/testcontainers-go/modules/redis" -) - -// sharedCache and sharedAddr are populated once by TestMain and reused by every test. -var ( - sharedCache cache.Cache - sharedAddr string -) - -// TestMain starts one Redis container for the whole suite, runs the tests, -// then terminates the container. -func TestMain(m *testing.M) { - ctx := context.Background() - - ctr, err := redis.Run(ctx, "redis:7-alpine") - if err != nil { - log.Fatalf("start redis container: %v", err) - } - - addr, err := ctr.ConnectionString(ctx) - if err != nil { - log.Fatalf("get connection string: %v", err) - } - - // ConnectionString returns "redis://host:port" — strip the scheme. - sharedAddr = addr[len("redis://"):] - - sharedCache = cache.NewRedisCache(sharedAddr) - - code := m.Run() - - _ = sharedCache.Close() - if err := ctr.Terminate(ctx); err != nil { - log.Printf("warn: terminate container: %v", err) - } - - os.Exit(code) -} - -// newCache returns the shared cache and registers a per-test key cleanup so -// tests do not interfere with each other. -func newCache(t *testing.T, keys ...string) cache.Cache { - t.Helper() - t.Cleanup(func() { - ctx := context.Background() - for _, k := range keys { - _ = sharedCache.Del(ctx, k) - } - }) - return sharedCache -} - -// ---- Tests ----------------------------------------------------------------- - -func TestPing(t *testing.T) { - c := newCache(t) - err := c.Ping(context.Background()) - assert.NoError(t, err) -} - -func TestSet_And_Get(t *testing.T) { - c := newCache(t, "set-get-key") - ctx := context.Background() - - require.NoError(t, c.Set(ctx, "set-get-key", "hello", time.Minute)) - - val, err := c.Get(ctx, "set-get-key") - require.NoError(t, err) - assert.Equal(t, "hello", val) -} - -func TestSet_Overwrites(t *testing.T) { - c := newCache(t, "overwrite-key") - ctx := context.Background() - - require.NoError(t, c.Set(ctx, "overwrite-key", "first", time.Minute)) - require.NoError(t, c.Set(ctx, "overwrite-key", "second", time.Minute)) - - val, err := c.Get(ctx, "overwrite-key") - require.NoError(t, err) - assert.Equal(t, "second", val) -} - -func TestSet_TTL_Expires(t *testing.T) { - c := newCache(t, "ttl-key") - ctx := context.Background() - - require.NoError(t, c.Set(ctx, "ttl-key", "value", 100*time.Millisecond)) - - time.Sleep(300 * time.Millisecond) - - _, err := c.Get(ctx, "ttl-key") - assert.Error(t, err, "key should have expired") -} - -func TestGet_Miss(t *testing.T) { - c := newCache(t) - ctx := context.Background() - - _, err := c.Get(ctx, "non-existent-key") - assert.Error(t, err) -} - -func TestDel_ExistingKey(t *testing.T) { - c := newCache(t, "del-key") - ctx := context.Background() - - require.NoError(t, c.Set(ctx, "del-key", "value", time.Minute)) - require.NoError(t, c.Del(ctx, "del-key")) - - _, err := c.Get(ctx, "del-key") - assert.Error(t, err) -} - -func TestDel_NonExistentKey(t *testing.T) { - c := newCache(t) - ctx := context.Background() - - // Del on a missing key must not error - err := c.Del(ctx, "missing-del-key") - assert.NoError(t, err) -} - -func TestSetNX_NewKey(t *testing.T) { - c := newCache(t, "setnx-key") - ctx := context.Background() - - ok, err := c.SetNX(ctx, "setnx-key", "value", time.Minute) - require.NoError(t, err) - assert.True(t, ok) - - val, err := c.Get(ctx, "setnx-key") - require.NoError(t, err) - assert.Equal(t, "value", val) -} - -func TestSetNX_ExistingKey(t *testing.T) { - c := newCache(t, "setnx-exists-key") - ctx := context.Background() - - require.NoError(t, c.Set(ctx, "setnx-exists-key", "original", time.Minute)) - - ok, err := c.SetNX(ctx, "setnx-exists-key", "new", time.Minute) - require.NoError(t, err) - assert.False(t, ok) - - val, err := c.Get(ctx, "setnx-exists-key") - require.NoError(t, err) - assert.Equal(t, "original", val) -} - -func TestDistributedLock(t *testing.T) { - c := newCache(t, "lock-key") - ctx := context.Background() - - // Acquire lock - ok, err := c.SetNX(ctx, "lock-key", "owner-1", 5*time.Second) - require.NoError(t, err) - require.True(t, ok, "first acquire must succeed") - - // Competing acquire must fail - ok, err = c.SetNX(ctx, "lock-key", "owner-2", 5*time.Second) - require.NoError(t, err) - assert.False(t, ok, "second acquire must fail while lock is held") - - // Release and re-acquire - require.NoError(t, c.Del(ctx, "lock-key")) - - ok, err = c.SetNX(ctx, "lock-key", "owner-2", 5*time.Second) - require.NoError(t, err) - assert.True(t, ok, "acquire after release must succeed") -} - -func TestDelIfValue(t *testing.T) { - c := newCache(t, "div-lock") - ctx := context.Background() - - require.NoError(t, c.Set(ctx, "div-lock", "owner-1", time.Minute)) - - deleted, err := c.DelIfValue(ctx, "div-lock", "owner-2") - require.NoError(t, err) - assert.False(t, deleted, "non-owner must not release the lock") - - deleted, err = c.DelIfValue(ctx, "div-lock", "owner-1") - require.NoError(t, err) - assert.True(t, deleted, "owner must release the lock") - - _, err = c.Get(ctx, "div-lock") - assert.True(t, cache.IsCacheMiss(err)) -} - -func TestCacheRefresh(t *testing.T) { - c := newCache(t, "refresh-key") - ctx := context.Background() - - require.NoError(t, c.Set(ctx, "refresh-key", "v1", time.Minute)) - - val, err := c.Get(ctx, "refresh-key") - require.NoError(t, err) - assert.Equal(t, "v1", val) - - require.NoError(t, c.Set(ctx, "refresh-key", "v2", time.Minute)) - - val, err = c.Get(ctx, "refresh-key") - require.NoError(t, err) - assert.Equal(t, "v2", val) - - require.NoError(t, c.Del(ctx, "refresh-key")) - - _, err = c.Get(ctx, "refresh-key") - assert.Error(t, err) -} - -func TestGetOrSet_Hit(t *testing.T) { - c := newCache(t, "gos-hit") - ctx := context.Background() - - require.NoError(t, c.Set(ctx, "gos-hit", "cached-value", time.Minute)) - - called := false - val, err := cacheaside.GetOrSet(ctx, cacheaside.GetOrSetRequest{Cache: c, Key: "gos-hit", TTL: time.Minute, Load: func(_ context.Context) (string, error) { - called = true - return "fn-value", nil - }}) - require.NoError(t, err) - assert.Equal(t, "cached-value", val) - assert.False(t, called) -} - -func TestGetOrSet_Miss(t *testing.T) { - c := newCache(t, "gos-miss") - ctx := context.Background() - - val, err := cacheaside.GetOrSet(ctx, cacheaside.GetOrSetRequest{Cache: c, Key: "gos-miss", TTL: time.Minute, Load: func(_ context.Context) (string, error) { - return "computed", nil - }}) - require.NoError(t, err) - assert.Equal(t, "computed", val) - - // Verify stored - stored, err := c.Get(ctx, "gos-miss") - require.NoError(t, err) - assert.Equal(t, "computed", stored) -} - -func TestGetOrSet_FnError(t *testing.T) { - c := newCache(t, "gos-err") - ctx := context.Background() - - _, err := cacheaside.GetOrSet(ctx, cacheaside.GetOrSetRequest{Cache: c, Key: "gos-err", TTL: time.Minute, Load: func(_ context.Context) (string, error) { - return "", assert.AnError - }}) - assert.Error(t, err) - - // Key must not be stored - _, err = c.Get(ctx, "gos-err") - assert.Error(t, err) -} - -func TestGetOrSet_ContextCancelled(t *testing.T) { - c := newCache(t) - ctx, cancel := context.WithCancel(context.Background()) - cancel() - - _, err := cacheaside.GetOrSet(ctx, cacheaside.GetOrSetRequest{Cache: c, Key: "gos-ctx", TTL: time.Minute, Load: func(_ context.Context) (string, error) { - return "value", nil - }}) - assert.Error(t, err) -} - -func TestGetOrSet_ThunderingHerd(t *testing.T) { - c := newCache(t, "gos-herd") - ctx := context.Background() - - var callCount atomic.Int32 - var wg sync.WaitGroup - n := 10 - - for range n { - wg.Go(func() { - val, err := cacheaside.GetOrSet(ctx, cacheaside.GetOrSetRequest{Cache: c, Key: "gos-herd", TTL: time.Minute, Load: func(_ context.Context) (string, error) { - callCount.Add(1) - time.Sleep(10 * time.Millisecond) - return "herd-value", nil - }}) - assert.NoError(t, err) - assert.Equal(t, "herd-value", val) - }) - } - wg.Wait() - - assert.Equal(t, int32(1), callCount.Load(), "fn must execute exactly once") -} - -// Real-world scenario: fetch user profile from simulated DB, cache result. -// Demonstrates cache-aside with stampede protection for a read-heavy profile endpoint. -func TestGetOrSet_UserProfileScenario(t *testing.T) { - c := newCache(t, "profile:user-42", "profile:user-stampede") - ctx := context.Background() - - // Simulated DB: user profiles keyed by ID. - type profile struct{ id, name, email string } - db := map[string]profile{ - "user-42": {id: "42", name: "Alice", email: "alice@example.com"}, - } - - // Simulate DB call counter. - var dbCallCount atomic.Int32 - - // Cache miss — GetOrSet calls fn (simulated DB query). - val, err := cacheaside.GetOrSet(ctx, cacheaside.GetOrSetRequest{Cache: c, Key: "profile:user-42", TTL: time.Minute, Load: func(_ context.Context) (string, error) { - dbCallCount.Add(1) - u, ok := db["user-42"] - if !ok { - return "", nil - } - return u.name + "|" + u.email, nil - }, Options: cacheaside.GetOrSetOptions{CacheNil: true}}) - require.NoError(t, err) - assert.Equal(t, "Alice|alice@example.com", val) - assert.Equal(t, int32(1), dbCallCount.Load(), "DB must be queried exactly once") - - // Second call — cache hit, no DB query. - val, err = cacheaside.GetOrSet(ctx, cacheaside.GetOrSetRequest{Cache: c, Key: "profile:user-42", TTL: time.Minute, Load: func(_ context.Context) (string, error) { - dbCallCount.Add(1) - return "should-not-reach", nil - }, Options: cacheaside.GetOrSetOptions{CacheNil: true}}) - require.NoError(t, err) - assert.Equal(t, "Alice|alice@example.com", val) - assert.Equal(t, int32(1), dbCallCount.Load(), "DB must NOT be queried on cache hit") - - // Stampede: fresh key with concurrent callers — fn called exactly once. - var wg sync.WaitGroup - dbCallCount.Store(0) - for range 10 { - wg.Go(func() { - val, err := cacheaside.GetOrSet(ctx, cacheaside.GetOrSetRequest{Cache: c, Key: "profile:user-stampede", TTL: time.Minute, Load: func(_ context.Context) (string, error) { - dbCallCount.Add(1) - time.Sleep(10 * time.Millisecond) - u := db["user-42"] - return u.name + "|" + u.email, nil - }, Options: cacheaside.GetOrSetOptions{CacheNil: true}}) - assert.NoError(t, err) - assert.Equal(t, "Alice|alice@example.com", val) - }) - } - wg.Wait() - assert.Equal(t, int32(1), dbCallCount.Load(), "concurrent requests must not trigger extra DB calls") -} - -// Redis unreachable: reads and writes fail, so GetOrSet degrades to the loader -// and reports each cache error. -func TestGetOrSet_RedisUnreachable(t *testing.T) { - ctx := context.Background() - down := cache.NewRedisCacheFromConfig(cache.RedisConfig{ - Addr: "127.0.0.1:1", // nothing listens here - DialTimeout: 100 * time.Millisecond, - }) - t.Cleanup(func() { _ = down.Close() }) - - var reported atomic.Int32 - var calls atomic.Int32 - val, err := cacheaside.GetOrSet(ctx, cacheaside.GetOrSetRequest{Cache: down, Key: "unreachable", TTL: time.Minute, Load: func(_ context.Context) (string, error) { - calls.Add(1) - return "from-loader", nil - }, Options: cacheaside.GetOrSetOptions{OnError: func(error) { reported.Add(1) }}}) - require.NoError(t, err) - assert.Equal(t, "from-loader", val) - assert.Equal(t, int32(1), calls.Load()) - assert.Positive(t, reported.Load()) -} - -// Real-world scenario: user not found — CacheNil prevents repeated DB lookups. -func TestGetOrSet_UserNotFoundScenario(t *testing.T) { - c := newCache(t, "profile:user-999") - ctx := context.Background() - - var dbCallCount atomic.Int32 - - // First call: user not found in DB, fn returns empty string. - val, err := cacheaside.GetOrSet(ctx, cacheaside.GetOrSetRequest{Cache: c, Key: "profile:user-999", TTL: time.Minute, Load: func(_ context.Context) (string, error) { - dbCallCount.Add(1) - return "", nil - }, Options: cacheaside.GetOrSetOptions{CacheNil: true}}) - require.NoError(t, err) - assert.Empty(t, val) - assert.Equal(t, int32(1), dbCallCount.Load()) - - // Second call: CacheNil hit — returns empty without calling fn. - val, err = cacheaside.GetOrSet(ctx, cacheaside.GetOrSetRequest{Cache: c, Key: "profile:user-999", TTL: time.Minute, Load: func(_ context.Context) (string, error) { - dbCallCount.Add(1) - return "should-not-reach", nil - }, Options: cacheaside.GetOrSetOptions{CacheNil: true}}) - require.NoError(t, err) - assert.Empty(t, val) - assert.Equal(t, int32(1), dbCallCount.Load(), "repeated not-found lookups must not hit DB") -} diff --git a/cache/go.mod b/cache/go.mod index 3c6098e..b07e5df 100644 --- a/cache/go.mod +++ b/cache/go.mod @@ -6,61 +6,13 @@ require ( github.com/alicebob/miniredis/v2 v2.40.0 github.com/redis/go-redis/v9 v9.23.0 github.com/stretchr/testify v1.12.1 - github.com/testcontainers/testcontainers-go/modules/redis v0.44.0 golang.org/x/sync v0.24.0 ) require ( - dario.cat/mergo v1.0.2 // indirect - github.com/Azure/go-ansiterm v0.0.0-20261013165250-51075c6ea6bc // indirect - github.com/Microsoft/go-winio v0.6.4 // indirect - github.com/cenkalti/backoff/v4 v4.3.0 // indirect github.com/cespare/xxhash/v2 v2.3.0 // indirect - github.com/containerd/errdefs v1.0.0 // indirect - github.com/containerd/errdefs/pkg v0.3.0 // indirect - github.com/containerd/log v0.2.0 // indirect - github.com/containerd/platforms v0.2.1 // indirect - github.com/cpuguy83/dockercfg v0.3.2 // indirect - github.com/distribution/reference v0.6.0 // indirect - github.com/docker/go-connections v0.8.2 // indirect - github.com/docker/go-units v0.5.0 // indirect - github.com/ebitengine/purego v0.11.1 // indirect - github.com/felixge/httpsnoop v1.1.0 // indirect - github.com/go-logr/logr v1.4.4 // indirect - github.com/go-logr/stdr v1.2.2 // indirect - github.com/go-ole/go-ole v1.3.0 // indirect - github.com/google/uuid v1.6.0 // indirect - github.com/klauspost/compress v1.20.3 // indirect - github.com/lufia/plan9stats v0.0.0-20260802145828-341c2f0c90b5 // indirect - github.com/magiconair/properties v1.18.12 // indirect - github.com/mdelapenya/tlscert v0.2.0 // indirect - github.com/moby/docker-image-spec v1.3.1 // indirect - github.com/moby/go-archive v0.3.3 // indirect - github.com/moby/moby/api v1.56.1 // indirect - github.com/moby/moby/client v0.6.2 // indirect - github.com/moby/patternmatcher v0.6.1 // indirect - github.com/moby/sys/sequential v0.7.0 // indirect - github.com/moby/sys/user v0.4.1 // indirect - github.com/moby/sys/userns v0.2.1 // indirect - github.com/moby/term v0.5.2 // indirect - github.com/opencontainers/go-digest v1.0.0 // indirect - github.com/opencontainers/image-spec v1.1.1 // indirect - github.com/power-devops/perfstat v0.0.0-20260916203055-22a1a467d9f0 // indirect - github.com/shirou/gopsutil/v4 v4.26.9 // indirect - github.com/sirupsen/logrus v1.10.2 // indirect - github.com/testcontainers/testcontainers-go v0.44.0 // indirect - github.com/tklauser/go-sysconf v0.4.0 // indirect - github.com/tklauser/numcpus v0.12.0 // indirect github.com/yuin/gopher-lua v1.1.2 // indirect - github.com/yusufpapurcu/wmi v1.2.4 // indirect - go.opentelemetry.io/auto/sdk v1.2.1 // indirect - go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.72.0 // indirect - go.opentelemetry.io/otel v1.47.0 // indirect - go.opentelemetry.io/otel/log v1.47.0 // indirect - go.opentelemetry.io/otel/metric v1.47.0 // indirect - go.opentelemetry.io/otel/trace v1.47.0 // indirect go.uber.org/atomic v1.12.0 // indirect go.yaml.in/yaml/v3 v3.0.5 // indirect - golang.org/x/crypto v0.58.0 // indirect golang.org/x/sys v0.49.0 // indirect ) diff --git a/cache/go.sum b/cache/go.sum index e488ff1..1c80c8f 100644 --- a/cache/go.sum +++ b/cache/go.sum @@ -1,149 +1,26 @@ -dario.cat/mergo v1.0.2 h1:85+piFYR1tMbRrLcDwR18y4UKJ3aH1Tbzi24VRW1TK8= -dario.cat/mergo v1.0.2/go.mod h1:E/hbnu0NxMFBjpMIE34DRGLWqDy0g5FuKDhCb31ngxA= -github.com/AdaLogics/go-fuzz-headers v0.0.0-20240806141605-e8a1dd7889d6 h1:He8afgbRMd7mFxO99hRNu+6tazq8nFF9lIwo9JFroBk= -github.com/AdaLogics/go-fuzz-headers v0.0.0-20240806141605-e8a1dd7889d6/go.mod h1:8o94RPi1/7XTJvwPpRSzSUedZrtlirdB3r9Z20bi2f8= -github.com/Azure/go-ansiterm v0.0.0-20261013165250-51075c6ea6bc h1:58s5YzGPNAP7+e1uemaL0ax/NPSeJOHdRpRIowd+JDk= -github.com/Azure/go-ansiterm v0.0.0-20261013165250-51075c6ea6bc/go.mod h1:DMNF6Kxv+EcuUvVuNkvC3f+BjEEmc/Fn9aU+qiD8zpU= -github.com/Microsoft/go-winio v0.6.4 h1:kJF2pamtYCWXf0xAT8sAkwKC0pMl2HYBrRPHAqyUc+g= -github.com/Microsoft/go-winio v0.6.4/go.mod h1:1xl5JXG4ze/m74GH6Dc4Mwxfc3VL5siRVQjIAlHH07U= github.com/alicebob/miniredis/v2 v2.40.0 h1:6IgTQbvm2JiMYZ8yur/acNJzVjtSOWCelxXbk/LUBXc= github.com/alicebob/miniredis/v2 v2.40.0/go.mod h1:TcL7YfarKPGDAthEtl5NBeHZfeUQj6OXMm/+iu5cLMM= github.com/bsm/ginkgo/v2 v2.12.0 h1:Ny8MWAHyOepLGlLKYmXG4IEkioBysk6GpaRTLC8zwWs= github.com/bsm/ginkgo/v2 v2.12.0/go.mod h1:SwYbGRRDovPVboqFv0tPTcG1sN61LM1Z4ARdbAV9g4c= github.com/bsm/gomega v1.27.10 h1:yeMWxP2pV2fG3FgAODIY8EiRE3dy0aeFYt4l7wh6yKA= github.com/bsm/gomega v1.27.10/go.mod h1:JyEr/xRbxbtgWNi8tIEVPUYZ5Dzef52k01W3YH0H+O0= -github.com/cenkalti/backoff/v4 v4.3.0 h1:MyRJ/UdXutAwSAT+s3wNd7MfTIcy71VQueUuFK343L8= -github.com/cenkalti/backoff/v4 v4.3.0/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE= github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs= github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= -github.com/containerd/errdefs v1.0.0 h1:tg5yIfIlQIrxYtu9ajqY42W3lpS19XqdxRQeEwYG8PI= -github.com/containerd/errdefs v1.0.0/go.mod h1:+YBYIdtsnF4Iw6nWZhJcqGSg/dwvV7tyJ/kCkyJ2k+M= -github.com/containerd/errdefs/pkg v0.3.0 h1:9IKJ06FvyNlexW690DXuQNx2KA2cUJXx151Xdx3ZPPE= -github.com/containerd/errdefs/pkg v0.3.0/go.mod h1:NJw6s9HwNuRhnjJhM7pylWwMyAkmCQvQ4GpJHEqRLVk= -github.com/containerd/log v0.2.0 h1:BewD/umNgVnoczglOpX8eRMyEy5t5iPlu5AIpnWDONc= -github.com/containerd/log v0.2.0/go.mod h1:/M7L7CXKcPTfNC74XzaK+5H5KbO5+4lJVpuVI6vRLoM= -github.com/containerd/platforms v0.2.1 h1:zvwtM3rz2YHPQsF2CHYM8+KtB5dvhISiXh5ZpSBQv6A= -github.com/containerd/platforms v0.2.1/go.mod h1:XHCb+2/hzowdiut9rkudds9bE5yJ7npe7dG/wG+uFPw= -github.com/cpuguy83/dockercfg v0.3.2 h1:DlJTyZGBDlXqUZ2Dk2Q3xHs/FtnooJJVaad2S9GKorA= -github.com/cpuguy83/dockercfg v0.3.2/go.mod h1:sugsbF4//dDlL/i+S+rtpIWp+5h0BHJHfjj5/jFyUJc= -github.com/creack/pty v1.1.24 h1:bJrF4RRfyJnbTJqzRLHzcGaZK1NeM5kTC9jGgovnR1s= -github.com/creack/pty v1.1.24/go.mod h1:08sCNb52WyoAwi2QDyzUCTgcvVFhUzewun7wtTfvcwE= -github.com/distribution/reference v0.6.0 h1:0IXCQ5g4/QMHHkarYzh5l+u8T3t73zM5QvfrDyIgxBk= -github.com/distribution/reference v0.6.0/go.mod h1:BbU0aIcezP1/5jX/8MP0YiH4SdvB5Y4f/wlDRiLyi3E= -github.com/docker/go-connections v0.8.2 h1:9d9DEokx5W7qlr0shkFXIxEA7+TTD+llwzcykSlxMNc= -github.com/docker/go-connections v0.8.2/go.mod h1:no1qkHdjq7kLMGUXYAduOhYPSJxxvgWBh7ogVvptn3Q= -github.com/docker/go-units v0.5.0 h1:69rxXcBk27SvSaaxTtLh/8llcHD8vYHT7WSdRZ/jvr4= -github.com/docker/go-units v0.5.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk= -github.com/ebitengine/purego v0.11.1 h1:2zpWRSQNVKN4eKsKO9eM1ILDgWfYMY9GwqRmK6XeQ/0= -github.com/ebitengine/purego v0.11.1/go.mod h1:DCHPP08djqhNSoTfImcnHYQRZmd0qhakvrozqaEYhGQ= -github.com/felixge/httpsnoop v1.1.0 h1:3YtUj32ZZkqZtt3sZZsClsymw/QDuVfpNhoA31zeORc= -github.com/felixge/httpsnoop v1.1.0/go.mod h1:Zqxgdd+1Rkcz8euOqdr7lqgCRJztwr5hp9vDSi5UZCE= -github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= -github.com/go-logr/logr v1.4.4 h1:tG4xh9yMsRCAiodLVTxyrkzSZ9+o0L1Kg/+cPVcbP/8= -github.com/go-logr/logr v1.4.4/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= -github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag= -github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE= -github.com/go-ole/go-ole v1.2.6/go.mod h1:pprOEPIfldk/42T2oK7lQ4v4JSDwmV0As9GaiUsvbm0= -github.com/go-ole/go-ole v1.3.0 h1:Dt6ye7+vXGIKZ7Xtk4s6/xVdGDQynvom7xCFEdWr6uE= -github.com/go-ole/go-ole v1.3.0/go.mod h1:5LS6F96DhAwUc7C+1HLexzMXY1xGRSryjyPPKW6zv78= -github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8= -github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU= -github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= -github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= -github.com/klauspost/compress v1.20.3 h1:zWNoFqq/lSuYQRim3dUXlXeA0IqwuZGicdG5ZTfY5j4= -github.com/klauspost/compress v1.20.3/go.mod h1:LUdAzn7YLVvxLpc7y3V1m40wESHTgc1422pwwBSKYuI= github.com/klauspost/cpuid/v2 v2.4.0 h1:S6Hrbc7+ywsr0r+RLapfGBHfyefhCTwEh3A0tV913Dw= github.com/klauspost/cpuid/v2 v2.4.0/go.mod h1:19jmZ9mjzoF//ddRSUsv0zfBTJWh3QJh9FNxZTMrGxU= -github.com/lufia/plan9stats v0.0.0-20260802145828-341c2f0c90b5 h1:eveIIGn4BGM3qknO74omf6HYr30/exH+eVUTuAgwjZ0= -github.com/lufia/plan9stats v0.0.0-20260802145828-341c2f0c90b5/go.mod h1:autxFIvghDt3jPTLoqZ9OZ7s9qTGNAWmYCjVFWPX/zg= -github.com/magiconair/properties v1.18.12 h1:sT9zQpvTB3B4gzrX0tmZNTEaGyg8Zw55MFYRE32Mr9I= -github.com/magiconair/properties v1.18.12/go.mod h1:Dhd985XPs7jluiymwWYZ0G4Z61jb3vdS329zhj2hYo0= -github.com/mdelapenya/tlscert v0.2.0 h1:7H81W6Z/4weDvZBNOfQte5GpIMo0lGYEeWbkGp5LJHI= -github.com/mdelapenya/tlscert v0.2.0/go.mod h1:O4njj3ELLnJjGdkN7M/vIVCpZ+Cf0L6muqOG4tLSl8o= -github.com/moby/docker-image-spec v1.3.1 h1:jMKff3w6PgbfSa69GfNg+zN/XLhfXJGnEx3Nl2EsFP0= -github.com/moby/docker-image-spec v1.3.1/go.mod h1:eKmb5VW8vQEh/BAr2yvVNvuiJuY6UIocYsFu/DxxRpo= -github.com/moby/go-archive v0.3.3 h1:OxxR9paxsluYi+zDUEXTTaIxtkK3viymW+Ka7vRhhME= -github.com/moby/go-archive v0.3.3/go.mod h1:Npdv43fFqlhZW7Xo8fbm3ZMYFvAGNviUPqX21VERbcE= -github.com/moby/moby/api v1.56.1 h1:PpWkvVPB7Fr/No8w+TfyJ/I6rWZ2YPZhT3JorIg+06c= -github.com/moby/moby/api v1.56.1/go.mod h1:sZ+THbVWkjOmBPPfbnzdD/G1LuIexWhqlSHHPTDQ1Uk= -github.com/moby/moby/client v0.6.2 h1:ekSPlMccrZGcw6Scb8T9D39qE0mB+XupU/yS0zNw9N4= -github.com/moby/moby/client v0.6.2/go.mod h1:DGcnO7qmPJrqobx/ggQgQ/AUk+2wgVdQv7uxB0/mEsc= -github.com/moby/patternmatcher v0.6.1 h1:qlhtafmr6kgMIJjKJMDmMWq7WLkKIo23hsrpR3x084U= -github.com/moby/patternmatcher v0.6.1/go.mod h1:hDPoyOpDY7OrrMDLaYoY3hf52gNCR/YOUYxkhApJIxc= -github.com/moby/sys/mount v0.3.5 h1:eS3fsZTjHaBihwjp4/+5Z3jxqLXYsbwxqpVSfFv3M00= -github.com/moby/sys/mount v0.3.5/go.mod h1:WUQDO+/uCiCIkIztx8SrwIDVn2dtMFRBebRhpDFT71M= -github.com/moby/sys/mountinfo v0.7.2 h1:1shs6aH5s4o5H2zQLn796ADW1wMrIwHsyJ2v9KouLrg= -github.com/moby/sys/mountinfo v0.7.2/go.mod h1:1YOa8w8Ih7uW0wALDUgT1dTTSBrZ+HiBLGws92L2RU4= -github.com/moby/sys/sequential v0.7.0 h1:ASQNGNROJSuOO6LL6bPHbKvuZu6NU8P4ldPWk31zj/8= -github.com/moby/sys/sequential v0.7.0/go.mod h1:NfSTAp6V3fw4tmkD62PEcOKeZKquXT8VKCkf7aVR79o= -github.com/moby/sys/user v0.4.1 h1:RgjRlaDKi/Xmyrz4t8lyzXT6v2ooFeO/7xtchmhVWE0= -github.com/moby/sys/user v0.4.1/go.mod h1:E9QsW5WRe1kUAf7kW8hXKwu1uhsZEAdPLYHYSDudF4Y= -github.com/moby/sys/userns v0.2.1 h1:4OvdM7BcPkASbuouHsbW3aeMJSFlYDldBRnXVZhaRk8= -github.com/moby/sys/userns v0.2.1/go.mod h1:IHUYgu/kao6N8YZlp9Cf444ySSvCmDlmzUcYfDHOl28= -github.com/moby/term v0.5.2 h1:6qk3FJAFDs6i/q3W/pQ97SX192qKfZgGjCQqfCJkgzQ= -github.com/moby/term v0.5.2/go.mod h1:d3djjFCrjnB+fl8NJux+EJzu0msscUP+f8it8hPkFLc= -github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8Oi/yOhh5U= -github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM= -github.com/opencontainers/image-spec v1.1.1 h1:y0fUlFfIZhPF1W537XOLg0/fcx6zcHCJwooC2xJA040= -github.com/opencontainers/image-spec v1.1.1/go.mod h1:qpqAh3Dmcf36wStyyWU+kCeDgrGnAve2nCC8+7h8Q0M= -github.com/power-devops/perfstat v0.0.0-20260916203055-22a1a467d9f0 h1:XA01Vk/wv9YikCi1V51yRzIHPMT5of9+cMpZoZvDn/M= -github.com/power-devops/perfstat v0.0.0-20260916203055-22a1a467d9f0/go.mod h1:OmDBASR4679mdNQnz2pUhc2G8CO2JrUAVFDRBDP/hJE= github.com/redis/go-redis/v9 v9.23.0 h1:/TTVdJa8BRNsybwwGGnmiYktHNlUXtbOQxlWpHBPL3s= github.com/redis/go-redis/v9 v9.23.0/go.mod h1:EWP2UUk+XDaI1s5nQB5mablZN6vccXlmBQTyfnF87D0= -github.com/shirou/gopsutil/v4 v4.26.9 h1:CaBo/hBFqvlJoLvAQEKdHdf5GD97/MN2ACfyv63+2Ig= -github.com/shirou/gopsutil/v4 v4.26.9/go.mod h1:nKH+8wX2zxr/mDbsR+AAy6Qd2z4ZOQ7wfQaEp+yrYmg= -github.com/sirupsen/logrus v1.10.2 h1:G2SED73/qrAu6YwbdxOD6peLkCBI3z7L+ykJFTXJBBo= -github.com/sirupsen/logrus v1.10.2/go.mod h1:SLEg8TqYulVKKfIGHldVp2K2aYz2DKSVBq4g/H5bR7Q= -github.com/stretchr/objx v0.5.3 h1:jmXUvGomnU1o3W/V5h2VEradbpJDwGrzugQQvL0POH4= -github.com/stretchr/objx v0.5.3/go.mod h1:rDQraq+vQZU7Fde9LOZLr8Tax6zZvy4kuNKF+QYS+U0= github.com/stretchr/testify v1.12.1 h1:EuwCh5fleGS7H32xRwO3wRGT7DxrDhLAT6FF8MpWDWE= github.com/stretchr/testify v1.12.1/go.mod h1:MDEgiDPPsNp5cuIrHPPCyornHKgEVbtFUmoNlxoYthg= -github.com/testcontainers/testcontainers-go v0.44.0 h1:/Fwh6HY1mIikhnm9e7HwoxGycx0lzRAE0f5VQpjFxzI= -github.com/testcontainers/testcontainers-go v0.44.0/go.mod h1:IcnwQrYTO86xHXu5bvMaBH7ATlbS3Qn1M1QWW3c66rE= -github.com/testcontainers/testcontainers-go/modules/redis v0.44.0 h1:43EH7N6yB5B2tY/9uhPit487tMLm5iQiyKQaXWXNbnk= -github.com/testcontainers/testcontainers-go/modules/redis v0.44.0/go.mod h1:k4nnCSzm3z8yRMBKBn3rhsllbFjjhVn/2JjWNxxArg8= -github.com/tklauser/go-sysconf v0.4.0 h1:7H0uAN+7RkwWRaxhYXDLqa5V3LPrJeV8wmD9dRUgPQU= -github.com/tklauser/go-sysconf v0.4.0/go.mod h1:8mTNWyog7H+MpKijp4VmKJAd2bbYQ2zuUwkYRbUArPI= -github.com/tklauser/numcpus v0.12.0 h1:NR85qdvHA9pFse3x3weVZ0r0ST8R6l5RHbZrlRaqob4= -github.com/tklauser/numcpus v0.12.0/go.mod h1:ABHeXzJnr/qqwguhClkZKT1/8VABcYrsyUiUGobwWJg= github.com/yuin/gopher-lua v1.1.2 h1:yF/FjE3hD65tBbt0VXLE13HWS9h34fdzJmrWRXwobGA= github.com/yuin/gopher-lua v1.1.2/go.mod h1:7aRmXIWl37SqRf0koeyylBEzJ+aPt8A+mmkQ4f1ntR8= -github.com/yusufpapurcu/wmi v1.2.4 h1:zFUKzehAFReQwLys1b/iSMl+JQGSCSjtVqQn9bBrPo0= -github.com/yusufpapurcu/wmi v1.2.4/go.mod h1:SBZ9tNy3G9/m5Oi98Zks0QjeHVDvuK0qfxQmPyzfmi0= github.com/zeebo/xxh3 v1.1.0 h1:s7DLGDK45Dyfg7++yxI0khrfwq9661w9EN78eP/UZVs= github.com/zeebo/xxh3 v1.1.0/go.mod h1:IisAie1LELR4xhVinxWS5+zf1lA4p0MW4T+w+W07F5s= -go.opentelemetry.io/auto/sdk v1.2.1 h1:jXsnJ4Lmnqd11kwkBV2LgLoFMZKizbCi5fNZ/ipaZ64= -go.opentelemetry.io/auto/sdk v1.2.1/go.mod h1:KRTj+aOaElaLi+wW1kO/DZRXwkF4C5xPbEe3ZiIhN7Y= -go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.72.0 h1:LxwW/9ctSCv+QkE/cLR7M91ZIkXNMqJtEMi1vCw9U8s= -go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.72.0/go.mod h1:tOsftB4SslBwwErVEPaenU2RpThXWPIU8DoJHEC4dyw= -go.opentelemetry.io/otel v1.47.0 h1:j7ALJ/zgkS7Z6aeJW09p8VC9804bC+PpeTfCD4XPnOM= -go.opentelemetry.io/otel v1.47.0/go.mod h1:8wS9O2qfXrYrzp6hIF/HOYJJf/wIhFPhR2xLuP+iXQU= -go.opentelemetry.io/otel/log v1.47.0 h1:cOTS1CcLbSQeZKanGJ+0JpF/+t4PELi3O3bbl2lqCcI= -go.opentelemetry.io/otel/log v1.47.0/go.mod h1:9byitSQ5pLC6PpqwGXjqdMKya6ZTswHRZh2vvXT33nw= -go.opentelemetry.io/otel/metric v1.47.0 h1:4PptaldXx3Eat1XjMZ68pPJEs5wrhlemctZE9a3UdWY= -go.opentelemetry.io/otel/metric v1.47.0/go.mod h1:ADGSXxRrXM6bjbvLo535EstVFlPpPYZm4LBKixjDHwU= -go.opentelemetry.io/otel/sdk v1.47.0 h1:zWXEr4j2lFefG87TU6Yg8a7ngfohIKFZHKp0Hf5hC6I= -go.opentelemetry.io/otel/sdk v1.47.0/go.mod h1:VUc24kiOeoGsxG8G9ULx3fWKvB7jMhnGE8Oi607lgR0= -go.opentelemetry.io/otel/sdk/metric v1.47.0 h1:lfISg2j93VT6yqdk9OfUaZmw/GfcZqCCV3jdXtsPnKw= -go.opentelemetry.io/otel/sdk/metric v1.47.0/go.mod h1:ypLp+mW1Nt2x+Szt3b5/i1syodyts49lMOwxpDI3VGw= -go.opentelemetry.io/otel/trace v1.47.0 h1:JOjX/Oci8K94QHddo+bbfya/Ai/nf6/dt9ZfrFNWSrM= -go.opentelemetry.io/otel/trace v1.47.0/go.mod h1:jNaSLa2PZEYFG6fRjJABAu+bw4FS08uDmPg28lTghu0= go.uber.org/atomic v1.12.0 h1:BvcXdFKuviU4fTL/f+SxdQ5qJX/Jix8pAkgdUcb3XOE= go.uber.org/atomic v1.12.0/go.mod h1:I6c4cg+6HCxRjfjSsYtApoFILnpc0CGUdGkXVqbYVNk= go.yaml.in/yaml/v3 v3.0.5 h1:N6y/pJk8buWs9NY5ERU2HSMfm+IuD/OtfdAnq6kESPw= go.yaml.in/yaml/v3 v3.0.5/go.mod h1:HVTZu1O7/Vkt2N+BFy8Zza+lnLsABggaTM2ZpNIGuKg= -golang.org/x/crypto v0.58.0 h1:COkYLr4k7nDI4r6QtMML2AfzeIswWHAJthLS6K/M/54= -golang.org/x/crypto v0.58.0/go.mod h1:Xh+kl5A+M0gMiWDytH2Hhr5Z7WbNCpv/eB/EFgfSk+w= golang.org/x/sync v0.24.0 h1:iqiDrGoDgyuvAKrhLQthUEzU/R378N78gXbBjxed7oA= golang.org/x/sync v0.24.0/go.mod h1:sUUOizhqBxiL6pEWpqNLUiaJn1ShEbZ6BBqskPbjZm0= -golang.org/x/sys v0.0.0-20190916202348-b4ddaad3f8a3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20201204225414-ed752295db88/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.49.0 h1:XbzkgYJHdqh/8m2Uu0W/dQv8nktxx4BFHp1M0gROTXA= golang.org/x/sys v0.49.0/go.mod h1:hNLxWAXmnKAxqDtdwIYC4bM9oQPEecfsnNMuSxOs3og= -golang.org/x/term v0.47.0 h1:cpyOwQkr2Nzxe2p6KnrTG7Ei2wtzjsuSjhpXXepZ/BM= -golang.org/x/term v0.47.0/go.mod h1:efAfAuG6RKABvg1ArGebRkvX6LXul14SM67o2e4mUCY= -gotest.tools/v3 v3.5.2 h1:7koQfIKdy+I8UTetycgUqXWSDwpgv193Ka+qRsmBY8Q= -gotest.tools/v3 v3.5.2/go.mod h1:LtdLGcnqToBH83WByAAi/wiwSFCArdFIUV/xxN4pcjA= -pgregory.net/rapid v1.2.0 h1:keKAYRcjm+e1F0oAuU5F5+YPAWcyxNNRK2wud503Gnk= -pgregory.net/rapid v1.2.0/go.mod h1:PY5XlDGj0+V1FCq0o192FdRhpKHGTRIWBgqjDBTrq04=