diff --git a/service/cachemdw/cache.go b/service/cachemdw/cache.go index 1f74dc2..a2202fa 100644 --- a/service/cachemdw/cache.go +++ b/service/cachemdw/cache.go @@ -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 diff --git a/service/cachemdw/errors.go b/service/cachemdw/errors.go new file mode 100644 index 0000000..225944c --- /dev/null +++ b/service/cachemdw/errors.go @@ -0,0 +1,5 @@ +package cachemdw + +import "errors" + +var ErrRequestIsNotCacheable = errors.New("request is not cacheable") diff --git a/service/cachemdw/is_cached_middleware.go b/service/cachemdw/is_cached_middleware.go index 64a3b6c..483aa11 100644 --- a/service/cachemdw/is_cached_middleware.go +++ b/service/cachemdw/is_cached_middleware.go @@ -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).