gofiber/fiber · error
cache: failed to get raw key
Error message
cache: failed to get raw key %q from storage: %w
What it means
Returned by manager.getRaw (the raw-body fetch path) when an external Storage's GetWithContext errors. Parallel to error 141 but for the separated raw response body (key+"_body") stored alongside the msgp metadata entry when cfg.Storage is configured.
Solutions
- Examine the wrapped error to classify (network vs context-cancellation vs protocol).
- Verify Storage health, connection pool, and timeouts.
- If intermittent, treat as cache miss and serve from the handler rather than failing the request.
- Ensure the raw-body key namespace is not evicted independently of the metadata key (consistent TTLs).
Example fix
// before
raw, err := m.storage.GetWithContext(ctx, key)
if err != nil {
return nil, fmt.Errorf("cache: failed to get raw key %q from storage: %w", m.logKey(key), err)
}
// after: degrade to miss on transient storage errors
raw, err := m.storage.GetWithContext(ctx, key)
if err != nil {
if errors.Is(err, context.Canceled) || errors.Is(err, context.DeadlineExceeded) {
return nil, err
}
return nil, errCacheMiss
} Defensive patterns
Strategy: retry
Validate before calling
// Verify the raw-body namespace is writable/readable before serving.
func probeRawBody(ctx context.Context, s fiber.Storage) error {
k := "__probe_body"
if err := s.SetWithContext(ctx, k, []byte("x"), time.Second); err != nil {
return err
}
if _, err := s.GetWithContext(ctx, k); err != nil {
return err
}
return s.DeleteWithContext(ctx, k)
} Try / catch
raw, err := m.storage.GetWithContext(ctx, key)
if err != nil {
if errors.Is(err, context.Canceled) || errors.Is(err, context.DeadlineExceeded) {
return nil, err
}
log.Warn("raw-body fetch failed, treating as miss:", err)
return nil, errCacheMiss
} Prevention
- Use the same TTL on raw-body and metadata keys so they expire together.
- Keep the raw-body key namespace consistent with the metadata namespace.
- Monitor Storage health to catch transient outages early.
When it happens
Trigger: Cache lookup on an external-Storage deployment where the body was stored separately; Storage.GetWithContext fails for the *_body key: backend down, timeout, connection error, context cancellation.
Common situations: Same as 141 — Redis/storage outage, pool exhaustion, client disconnect propagating context cancellation, TLS/auth issues, failover. Surfaces specifically on the second leg of a two-key cache lookup.
Related errors
- cache: failed to store raw key
- cache: failed to delete key
- cache: failed to get key
- cache: failed to store key
- cache: failed to delete raw key
AI-assisted analysis of gofiber/fiber@a105acad6c (2026-08-11).
Data as JSON: /api/errors/70a9641c5bb2fe5b.
Report an issue: GitHub.
Appendix: source
Thrown at middleware/cache/manager.go:145
}
if value := m.memory.Get(key); value != nil {
it, ok := value.(*item)
if !ok {
return nil, fmt.Errorf("cache: unexpected entry type %T for key %q", value, m.logKey(key))
}
return it, nil
}
return nil, errCacheMiss
}
// get raw data from storage or memory
func (m *manager) getRaw(ctx context.Context, key string) ([]byte, error) {
if m.storage != nil {
raw, err := m.storage.GetWithContext(ctx, key)
if err != nil {
return nil, fmt.Errorf("cache: failed to get raw key %q from storage: %w", m.logKey(key), err)
}
if raw == nil {
return nil, errCacheMiss
}
return raw, nil
}
if value := m.memory.Get(key); value != nil {
raw, ok := value.([]byte)
if !ok {
return nil, fmt.Errorf("cache: unexpected raw entry type %T for key %q", value, m.logKey(key))
}
return raw, nil
}
return nil, errCacheMiss
}
View on GitHub (pinned to a105acad6c)