{"record":{"id":"10c2645d32c5a59e","repo":"micro/go-micro","slug":"erritemexpired","errorCode":"ErrItemExpired","errorMessage":"item has expired","messagePattern":"item has expired","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"cache/cache.go","lineNumber":18,"sourceCode":"package cache\n\nimport (\n\t\"context\"\n\t\"errors\"\n\t\"time\"\n)\n\nvar (\n\t// DefaultCache is the default cache.\n\tDefaultCache Cache = NewCache()\n\t// DefaultExpiration is the default duration for items stored in\n\t// the cache to expire.\n\tDefaultExpiration time.Duration = 0\n\n\t// ErrItemExpired is returned in Cache.Get when the item found in the cache\n\t// has expired.\n\tErrItemExpired error = errors.New(\"item has expired\")\n\t// ErrKeyNotFound is returned in Cache.Get and Cache.Delete when the\n\t// provided key could not be found in cache.\n\tErrKeyNotFound error = errors.New(\"key not found in cache\")\n)\n\n// Cache is the interface that wraps the cache.\ntype Cache interface {\n\t// Get gets a cached value by key.\n\tGet(ctx context.Context, key string) (interface{}, time.Time, error)\n\t// Put stores a key-value pair into cache.\n\tPut(ctx context.Context, key string, val interface{}, d time.Duration) error\n\t// Delete removes a key from cache.\n\tDelete(ctx context.Context, key string) error\n\t// String returns the name of the implementation.\n\tString() string\n}\n\n// Item represents an item stored in the cache.","sourceCodeStart":1,"sourceCodeEnd":36,"githubUrl":"https://github.com/micro/go-micro/blob/24529f140421a11a33b6999ab7944f2021cfd69c/cache/cache.go#L1-L36","documentation":"ErrItemExpired is a sentinel error returned by Cache.Get when the requested key exists in the cache but its TTL has elapsed. The cache distinguishes expired entries from missing keys so callers can react to staleness differently from absence. It is declared in cache/cache.go:18 alongside DefaultExpiration, which controls when entries expire.","triggerScenarios":"Calling Cache.Get (or anything built on it) for a key whose stored entry's expiration timestamp is earlier than the current time. Also occurs when an item was stored with DefaultExpiration and the cache's default TTL elapsed.","commonSituations":"Session or token caches where entries outlive their TTL; long-running workers re-reading cached config that expired between iterations; tests asserting on cached values after advancing clocks or using very short expirations.","solutions":["Re-fetch the underlying value from the source of truth and re-store it with Cache.Put/Set before retrying Get","Check errors.Is(err, cache.ErrItemExpired) explicitly and treat it as a cache miss rather than a hard failure","Increase the TTL (or use a longer DefaultExpiration) when storing items that should live longer","Prefer Cache.Get with a longer-lived cache layer (e.g. persistent store) behind it for expensive reads"],"exampleFix":"// before\nv, _, err := cache.Get(ctx, \"user:1\")\nif err != nil { return err }\n// after\nv, _, err := cache.Get(ctx, \"user:1\")\nif errors.Is(err, cache.ErrItemExpired) || errors.Is(err, cache.ErrKeyNotFound) {\n    v = loadUserFromDB(1)\n    _ = cache.Put(ctx, \"user:1\", v, 10*time.Minute)\n}","handlingStrategy":"fallback","validationCode":"if exp, ok := expiryFromStore(key); ok && time.Now().After(exp) {\n    // entry will be reported expired; refresh proactively\n    refreshEntry(key)\n}","typeGuard":"func isExpired(err error) bool { return errors.Is(err, cache.ErrItemExpired) }","tryCatchPattern":"v, _, err := cache.Get(ctx, key)\nif isExpired(err) || errors.Is(err, cache.ErrKeyNotFound) {\n    v = reloadFromSource(ctx, key)\n    _ = cache.Put(ctx, key, v, ttl)\n} else if err != nil {\n    return err\n}","preventionTips":["Always treat ErrItemExpired as a miss, not a failure","Set TTLs with margin relative to your refresh interval","Monitor expiry rates to size TTLs appropriately"],"tags":["cache","expiration","ttl","go"],"backgroundTag":"cache-entry-expired","analyzedSha":"24529f140421a11a33b6999ab7944f2021cfd69c","analyzedAt":"2026-09-01T02:52:24.923Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}