Skip to content

Commit

Permalink
Merge pull request #533 from OdyseeTeam/improve-cache-retry
Browse files Browse the repository at this point in the history
Improve cache retry
  • Loading branch information
anbsky authored Jan 7, 2025
2 parents 5ad4e33 + 6916832 commit 15a2b2a
Show file tree
Hide file tree
Showing 13 changed files with 103 additions and 1,077 deletions.
8 changes: 8 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
linters-settings:
errcheck:
check-type-assertions: true
gci:
sections:
- standard
- prefix(github.com/lbryio)
- prefix(github.com/OdyseeTeam)
- default
custom-order: true
goconst:
min-len: 2
min-occurrences: 3
Expand All @@ -9,6 +16,7 @@ linters:
disable-all: true
enable:
- dupl
- gci
- gocritic
- goconst
- gocyclo
Expand Down
24 changes: 2 additions & 22 deletions app/query/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,11 @@ import (

"github.com/OdyseeTeam/odysee-api/internal/monitor"
"github.com/OdyseeTeam/odysee-api/pkg/chainquery"
"github.com/OdyseeTeam/odysee-api/pkg/rpcerrors"
"github.com/pierrec/lz4"

"github.com/eko/gocache/lib/v4/cache"
"github.com/eko/gocache/lib/v4/marshaler"
"github.com/eko/gocache/lib/v4/store"
"github.com/pierrec/lz4"
"github.com/ybbus/jsonrpc/v2"
"golang.org/x/sync/singleflight"
)
Expand Down Expand Up @@ -102,8 +101,8 @@ func (c *QueryCache) Retrieve(query *Query, getter func() (any, error)) (*Cached
return nil, nil
}

log.Infof("cache miss for %s, key=%s, duration=%.2fs", cacheReq.Method, cacheReq.GetCacheKey(), time.Since(start).Seconds())
// Cold object retrieval after cache miss
log.Infof("cache miss for %s, key=%s, duration=%.2fs", cacheReq.Method, cacheReq.GetCacheKey(), time.Since(start).Seconds())
start := time.Now()
obj, err, _ := c.singleflight.Do(cacheReq.GetCacheKey(), getter)
if err != nil {
Expand Down Expand Up @@ -251,22 +250,3 @@ func (r *CachedResponse) UnmarshalBinary(data []byte) error {
decoder.UseNumber()
return decoder.Decode(r)
}

func preflightCacheHook(caller *Caller, ctx context.Context) (*jsonrpc.RPCResponse, error) {
log := logger.Log()
if caller.Cache == nil {
log.Warn("no cache present on caller")
return nil, nil
}
query := QueryFromContext(ctx)
cachedResp, err := caller.Cache.Retrieve(query, func() (any, error) {
return caller.SendQuery(ctx, query)
})
if err != nil {
return nil, rpcerrors.NewSDKError(err)
}
if cachedResp == nil {
return nil, nil
}
return cachedResp.RPCResponse(query.Request.ID), nil
}
135 changes: 0 additions & 135 deletions app/query/cache/cache.go

This file was deleted.

101 changes: 0 additions & 101 deletions app/query/cache/cache_test.go

This file was deleted.

34 changes: 0 additions & 34 deletions app/query/cache/middleware.go

This file was deleted.

Loading

0 comments on commit 15a2b2a

Please sign in to comment.