diff --git a/cache.go b/cache.go index 0c36711..8457794 100644 --- a/cache.go +++ b/cache.go @@ -166,12 +166,12 @@ func (c *Cache) Set(key string, data any) error { ExpiresAt: time.Now().Add(ttl), } - entryResult := core.JSONMarshal(entry) - if !entryResult.OK { - return core.E("cache.Set", "failed to marshal cache entry", entryResult.Value.(error)) + entryBytes, err := json.MarshalIndent(entry, "", " ") + if err != nil { + return core.E("cache.Set", "failed to marshal cache entry", err) } - if err := c.medium.Write(path, string(entryResult.Value.([]byte))); err != nil { + if err := c.medium.Write(path, string(entryBytes)); err != nil { return core.E("cache.Set", "failed to write cache file", err) } return nil diff --git a/cache_test.go b/cache_test.go index b38f57b..4011543 100644 --- a/cache_test.go +++ b/cache_test.go @@ -3,6 +3,7 @@ package cache_test import ( + "strings" "testing" "time" @@ -60,6 +61,9 @@ func TestCache_New_Good(t *testing.T) { if err != nil { t.Fatalf("Read failed: %v", err) } + if !strings.Contains(raw, "\n \"data\":") { + t.Fatalf("expected pretty-printed cache entry, got %q", raw) + } entry := readEntry(t, raw) ttl := entry.ExpiresAt.Sub(entry.CachedAt)