Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve get-cached-response method #52

Merged
merged 1 commit into from
Oct 31, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions service/cachemdw/cache.go
Original file line number Diff line number Diff line change
@@ -90,6 +90,12 @@ func (c *ServiceCache) GetCachedQueryResponse(
ctx context.Context,
req *decode.EVMRPCRequestEnvelope,
) ([]byte, error) {
// if request isn't cacheable - there is no point to try to get it from cache so exit early with an error
cacheable := IsCacheable(c.ServiceLogger, req)
if !cacheable {
return nil, ErrRequestIsNotCacheable
}

key, err := GetQueryKey(c.cachePrefix, req)
if err != nil {
return nil, err
5 changes: 5 additions & 0 deletions service/cachemdw/errors.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package cachemdw

import "errors"

var ErrRequestIsNotCacheable = errors.New("request is not cacheable")
2 changes: 1 addition & 1 deletion service/cachemdw/is_cached_middleware.go
Original file line number Diff line number Diff line change
@@ -61,7 +61,7 @@ func (c *ServiceCache) IsCachedMiddleware(
// 1. if not cached or we encounter an error then mark as uncached and forward to next middleware
// 2. if cached then mark as cached, set cached response in context and forward to next middleware
cachedQueryResponse, err := c.GetCachedQueryResponse(r.Context(), decodedReq)
if err != nil && err != cache.ErrNotFound {
if err != nil && err != cache.ErrNotFound && err != ErrRequestIsNotCacheable {
// log unexpected error
c.Logger.Error().
Err(err).