{"record":{"id":"055abd1eaf03fdb9","repo":"gofiber/fiber","slug":"cache-failed-to-store-key-q-w","errorCode":null,"errorMessage":"cache: failed to store key %q: %w","messagePattern":"cache: failed to store key %q: %w","errorType":"http","errorClass":null,"httpStatus":500,"severity":"error","filePath":"middleware/cache/manager.go","lineNumber":174,"sourceCode":"\t\t\treturn nil, fmt.Errorf(\"cache: unexpected raw entry type %T for key %q\", value, m.logKey(key))\n\t\t}\n\t\treturn raw, nil\n\t}\n\n\treturn nil, errCacheMiss\n}\n\n// set data to storage or memory\nfunc (m *manager) set(ctx context.Context, key string, it *item, exp time.Duration) error {\n\tif m.storage != nil {\n\t\traw, err := it.MarshalMsg(nil)\n\t\tif err != nil {\n\t\t\tm.release(it)\n\t\t\treturn fmt.Errorf(\"cache: failed to marshal key %q: %w\", m.logKey(key), err)\n\t\t}\n\t\tif err := m.storage.SetWithContext(ctx, key, raw, exp); err != nil {\n\t\t\tm.release(it)\n\t\t\treturn fmt.Errorf(\"cache: failed to store key %q: %w\", m.logKey(key), err)\n\t\t}\n\t\tm.release(it)\n\t\treturn nil\n\t}\n\n\tm.memory.Set(key, it, exp)\n\treturn nil\n}\n\n// set data to storage or memory\nfunc (m *manager) setRaw(ctx context.Context, key string, raw []byte, exp time.Duration) error {\n\tif m.storage != nil {\n\t\tif err := m.storage.SetWithContext(ctx, key, raw, exp); err != nil {\n\t\t\treturn fmt.Errorf(\"cache: failed to store raw key %q: %w\", m.logKey(key), err)\n\t\t}\n\t\treturn nil\n\t}\n","sourceCodeStart":156,"sourceCodeEnd":192,"githubUrl":"https://github.com/gofiber/fiber/blob/a105acad6c1e4576a77f01e02973f67e962bb58d/middleware/cache/manager.go#L156-L192","documentation":"Returned by manager.set when the external Storage's SetWithContext fails after successful msgp serialization. The metadata entry could not be persisted; the item is released back to the pool and the cache write is aborted.","triggerScenarios":"Cache store path (cfg.Storage set) where Storage.SetWithContext returns an error: backend down, write timeout, max-memory/quota exceeded on Redis, network error, context cancellation mid-write.","commonSituations":"Redis maxmemory eviction policies dropping writes, backend at capacity, network blips, TLS/auth mismatch, storage driver write timeouts too tight under load, client disconnect cancelling the request context.","solutions":["Inspect the wrapped Storage error to identify the cause (capacity, network, auth).","Check backend memory/quota and eviction policy (Redis maxmemory-policy).","Increase write timeout and connection pool size if the error correlates with load.","Treat the cache as advisory: log and proceed uncached rather than failing the user request."],"exampleFix":"// Cache writes are advisory — isolate them from the response path:\nif err := manager.set(reqCtx, key, e, exp); err != nil {\n    log.Warn(\"cache store failed; serving uncached:\", err)\n    // do NOT return err to the client; the handler result is still valid\n}","handlingStrategy":"retry","validationCode":"func storageWritable(ctx context.Context, s fiber.Storage) error {\n    return s.SetWithContext(ctx, \"__wprobe__\", []byte(\"ok\"), time.Second)\n}","typeGuard":null,"tryCatchPattern":"// Cache writes are advisory; isolate from the response path.\nif err := manager.set(reqCtx, key, e, exp); err != nil {\n    if errors.Is(err, context.Canceled) || errors.Is(err, context.DeadlineExceeded) {\n        return // client gone\n    }\n    log.Warn(\"cache metadata store failed; serving uncached:\", err)\n}","preventionTips":["Treat cache store failures as non-fatal; log and continue.","Provision Storage capacity headroom and a permissive eviction policy.","Tune write timeouts to your Storage p99."],"tags":["cache","storage","network","write","go","fiber"],"backgroundTag":null,"analyzedSha":"a105acad6c1e4576a77f01e02973f67e962bb58d","analyzedAt":"2026-08-11T17:33:26.942Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}