gofiber/fiber · info

cache: no cached body for key

Error message

cache: no cached body for key %q: %w

What it means

Wrapped by cacheBodyFetchError specifically around errCacheMiss: it converts the sentinel cache miss into a descriptive error naming the (masked) key. This is not a fault — it is the normal 'no cached body for this key' signal, and is the expected control-flow outcome for cache misses on the body-fetch path.

Solutions

  1. Detect this case with errors.Is(err, errCacheMiss) and treat it as a miss (proceed to handler), not as an error.
  2. Do not log it at error level — log at debug/trace or not at all.
  3. Verify the cache key/namespace and expiration are configured as expected if misses are unexpectedly high.
  4. Confirm Storage connectivity if misses persist where hits were expected (a separate storage error would surface as 141/144 instead).

Example fix

// before: treating the wrapped miss as an error
if err := fetchBody(); err != nil {
    return err // wrongly fails the request on a normal miss
}

// after: unwrap and branch on the sentinel
if err := fetchBody(); err != nil {
    if errors.Is(err, errCacheMiss) {
        // proceed to handler — this is a cache miss, not a fault
    } else {
        return err
    }
}
Defensive patterns

Strategy: fallback

Validate before calling

// Distinguish a miss from a real error before branching.
func isCacheMiss(err error) bool {
    return errors.Is(err, errCacheMiss)
}

Try / catch

// This is control flow, not an error.
if err := fetchCachedBody(); err != nil {
    if errors.Is(err, errCacheMiss) {
        // proceed to handler — normal miss
        return handler(c)
    }
    return err // genuine storage error
}

Prevention

When it happens

Trigger: Produced whenever the cache attempts to fetch a stored body and the underlying manager returns errCacheMiss (key absent in storage/memory, or storage returned nil bytes). Triggered on every genuine cache miss where the body is requested separately.

Common situations: Normal first request to an uncached route; entry expired/TTL'd out; cold start with empty cache; after explicit cache purge. Should be treated as a hit/miss signal, not an operational error.

Related errors


AI-assisted analysis of gofiber/fiber@a105acad6c (2026-08-11). Data as JSON: /api/errors/ad96a526728d67c5. Report an issue: GitHub.

Appendix: source

Thrown at middleware/cache/utils.go:23

	"encoding/binary"
	"encoding/hex"
	"errors"
	"fmt"
	"math"
	"strings"
	"sync"
	"time"

	"github.com/gofiber/fiber/v3"
	"github.com/gofiber/fiber/v3/internal/fieldname"
	"github.com/gofiber/fiber/v3/internal/mediatype"
	"github.com/gofiber/utils/v2"
	"github.com/valyala/fasthttp"
)

func cacheBodyFetchError(mask func(string) string, key string, err error) error {
	if errors.Is(err, errCacheMiss) {
		return fmt.Errorf("cache: no cached body for key %q: %w", mask(key), err)
	}
	return err
}

func cachedResponseAge(e *item, now uint64) uint64 {
	clampedDate := clampDateSeconds(e.date, now)

	resident := uint64(0)
	if e.exp != 0 {
		if e.exp <= now {
			resident = e.ttl + (now - e.exp)
		} else {
			resident = e.ttl - (e.exp - now)
		}
	}

	dateAge := uint64(0)
	if clampedDate != 0 && now > clampedDate {

View on GitHub (pinned to a105acad6c)