chore: custom error

This commit is contained in:
2026-03-02 22:38:28 +01:00
parent 6c1387c1cd
commit 2491d21963
19 changed files with 363 additions and 60 deletions
+7 -7
View File
@@ -22,7 +22,7 @@ func (c *CachedClient) Read(path string) ([]byte, error) {
ctx := context.Background()
// Try cache
cached, err := c.client.Do(ctx, c.client.B().Get().Key(key).Build()).AsBytes()
cached, err := c.cache.Do(ctx, c.cache.B().Get().Key(key).Build()).AsBytes()
if err == nil && len(cached) > 0 {
c.readHits.Add(1)
c.hits.Add(1)
@@ -58,7 +58,7 @@ func (c *CachedClient) Read(path string) ([]byte, error) {
}
// Cache
c.client.Do(ctx, c.client.B().Set().Key(key).Value(valkey.BinaryString(cached)).Ex(c.ttl).Build())
c.cache.Do(ctx, c.cache.B().Set().Key(key).Value(valkey.BinaryString(cached)).Ex(c.ttl).Build())
return data, nil
}
@@ -67,7 +67,7 @@ func (c *CachedClient) revalidateRead(ctx context.Context) {
startTime := time.Now()
c.scanAndProcess(ctx, keyRead+"*", func(key string) error {
path := strings.TrimPrefix(key, keyRead)
cached, err := c.client.Do(ctx, c.client.B().Get().Key(key).Build()).AsBytes()
cached, err := c.cache.Do(ctx, c.cache.B().Get().Key(key).Build()).AsBytes()
if err != nil {
// Key might be gone or error fetching
return nil
@@ -76,13 +76,13 @@ func (c *CachedClient) revalidateRead(ctx context.Context) {
var cachedFile readFile
err = json.Unmarshal(cached, &cachedFile)
if err != nil {
c.client.Do(ctx, c.client.B().Del().Key(key).Build())
c.cache.Do(ctx, c.cache.B().Del().Key(key).Build())
return err
}
info, err := c.impl.Stat(path)
if err != nil {
c.client.Do(ctx, c.client.B().Del().Key(key).Build())
c.cache.Do(ctx, c.cache.B().Del().Key(key).Build())
return nil
}
@@ -99,9 +99,9 @@ func (c *CachedClient) revalidateRead(ctx context.Context) {
return err
}
c.client.Do(ctx, c.client.B().Set().Key(key).Value(valkey.BinaryString(newCached)).Ex(c.ttl).Build())
c.cache.Do(ctx, c.cache.B().Set().Key(key).Value(valkey.BinaryString(newCached)).Ex(c.ttl).Build())
} else {
c.client.Do(ctx, c.client.B().Expire().Key(key).Seconds(int64(c.ttl/time.Second)).Build())
c.cache.Do(ctx, c.cache.B().Expire().Key(key).Seconds(int64(c.ttl/time.Second)).Build())
}
return nil
})