gofiber/fiber · error
cache: failed to delete key
Error message
cache: failed to delete key %q: %w
What it means
Returned by manager.del when the external Storage's DeleteWithContext fails. Deletion is invoked during cache invalidation/eviction and during cleanup paths; failure here leaves a stale or orphaned entry in the backend.
Solutions
- Check the wrapped error for permission (ACL) vs connectivity vs cancellation causes.
- Ensure the configured Storage credentials have DEL permission.
- Rely on TTL/expiration to eventually purge entries if explicit delete fails; do not fail the user request over a cleanup delete.
- Verify connection pool health if deletes fail under load.
Example fix
// before: surfacing delete failure from invalidation
if err := manager.del(ctx, key); err != nil {
return err
}
// after: invalidation is best-effort; TTL is the safety net
if err := manager.del(ctx, key); err != nil {
log.Warn("cache delete failed; entry will expire via TTL:", err)
} Defensive patterns
Strategy: try-catch
Validate before calling
func storageDeletable(ctx context.Context, s fiber.Storage) error {
if err := s.SetWithContext(ctx, "__dprobe__", []byte("x"), time.Second); err != nil {
return err
}
return s.DeleteWithContext(ctx, "__dprobe__")
} Try / catch
// Cache deletes are best-effort; TTL is the backstop.
if err := manager.del(ctx, key); err != nil {
log.Warn("cache delete failed; entry will expire via TTL:", err)
} Prevention
- Grant the Storage credentials DEL permission.
- Keep TTLs short enough that failed deletes self-heal.
- Do not block request handling on cache invalidation.
When it happens
Trigger: Any path calling manager.del (cache invalidation, MaxBytes eviction cleanup, store-error cleanup) against a Storage backend whose DeleteWithContext errors: backend down, network error, permission/ACL denial on DEL, context cancellation.
Common situations: Redis ACL missing the DEL permission; backend transient outage during an eviction; client disconnect during invalidation; storage driver connection pool exhausted under churn.
Related errors
- cache: failed to get key
- cache: failed to get raw key
- cache: failed to store key
- cache: failed to store raw key
- csrf: failed to delete key
AI-assisted analysis of gofiber/fiber@a105acad6c (2026-08-11).
Data as JSON: /api/errors/23f067e76f113559.
Report an issue: GitHub.
Appendix: source
Thrown at middleware/cache/manager.go:201
// set data to storage or memory
func (m *manager) setRaw(ctx context.Context, key string, raw []byte, exp time.Duration) error {
if m.storage != nil {
if err := m.storage.SetWithContext(ctx, key, raw, exp); err != nil {
return fmt.Errorf("cache: failed to store raw key %q: %w", m.logKey(key), err)
}
return nil
}
m.memory.Set(key, raw, exp)
return nil
}
// delete data from storage or memory
func (m *manager) del(ctx context.Context, key string) error {
if m.storage != nil {
if err := m.storage.DeleteWithContext(ctx, key); err != nil {
return fmt.Errorf("cache: failed to delete key %q: %w", m.logKey(key), err)
}
return nil
}
m.memory.Delete(key)
return nil
}
func (m *manager) logKey(key string) string {
if m.shouldRedactKeys {
return redactedKey
}
return key
}
View on GitHub (pinned to a105acad6c)