Skip to content

Commit 6fd44fb

Browse files
vishrclaude
andcommitted
Fix cache effectiveness test by clearing cache state
- Add Clear() method to Cache struct - Clear cache at start of TestCacheEffectiveness to ensure fresh state - Prevents test failures when cache is warmed by previous tests 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent 4c7df56 commit 6fd44fb

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

cookbook/performance/server.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ func (c *Cache) Set(key string, value any) {
4444
c.data[key] = value
4545
}
4646

47+
func (c *Cache) Clear() {
48+
c.data = make(map[string]any)
49+
}
50+
4751
var cache = NewCache()
4852

4953
// Fast endpoint - minimal processing

cookbook/performance/server_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,9 @@ func TestResponseTime(t *testing.T) {
135135
}
136136

137137
func TestCacheEffectiveness(t *testing.T) {
138+
// Clear cache to ensure fresh test state
139+
cache.Clear()
140+
138141
e := echo.New()
139142
req := httptest.NewRequest(http.MethodGet, "/cached", nil)
140143

0 commit comments

Comments
 (0)