fix(api): 管理后台成功写入后递增缓存代次 (#40)

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
fu500f
2026-10-31 00:45:55 +00:00
co-authored by Devin AI
parent 36f9c95fa7
commit d0ad1b85f3
6 changed files with 161 additions and 13 deletions
+11 -7
View File
@@ -22,6 +22,15 @@ func TestDisabledFailsOpen(t *testing.T) {
}
}
func TestBumpDisabledCache(t *testing.T) {
if err := (*Cache)(nil).Bump(context.Background()); err != nil {
t.Fatalf("nil cache Bump(): %v", err)
}
if err := (&Cache{}).Bump(context.Background()); err != nil {
t.Fatalf("disabled cache Bump(): %v", err)
}
}
func testCache(t *testing.T) *Cache {
t.Helper()
url := os.Getenv("OPENGOODS_REDIS_URL")
@@ -69,14 +78,9 @@ func TestEpochInvalidation(t *testing.T) {
t.Fatal("expected hit before epoch bump")
}
// Simulate an ingestion write bumping the global epoch.
if err := c.rdb.Incr(ctx, epochKey).Err(); err != nil {
t.Fatalf("incr epoch: %v", err)
if err := c.Bump(ctx); err != nil {
t.Fatalf("bump epoch: %v", err)
}
// Force the process to re-read the epoch rather than use its cached value.
c.mu.Lock()
c.epochOK = false
c.mu.Unlock()
if c.GetJSON(ctx, suffix, &dst) {
t.Fatal("entry should be invisible after epoch bump")