{"record":{"id":"4589b0eb41b133b7","repo":"spring-projects/spring-ai","slug":"failed-to-update-cached-content","errorCode":null,"errorMessage":"Failed to update cached content: ","messagePattern":"Failed to update cached content: ","errorType":"exception","errorClass":"CachedContentException","httpStatus":null,"severity":"error","filePath":"models/spring-ai-google-genai/src/main/java/org/springframework/ai/google/genai/cache/GoogleGenAiCachedContentService.java","lineNumber":166,"sourceCode":"\t\t}\n\n\t\tif (request.getExpireTime() != null) {\n\t\t\tconfigBuilder.expireTime(request.getExpireTime());\n\t\t}\n\n\t\ttry {\n\t\t\tUpdateCachedContentConfig config = configBuilder.build();\n\t\t\tCachedContent cachedContent = this.caches.update(name, config);\n\t\t\tif (logger.isDebugEnabled()) {\n\t\t\t\tlogger.debug(\"Updated cached content: \" + name);\n\t\t\t}\n\t\t\treturn GoogleGenAiCachedContent.from(cachedContent);\n\t\t}\n\t\tcatch (Exception e) {\n\t\t\tif (logger.isErrorEnabled()) {\n\t\t\t\tlogger.error(\"Failed to update cached content: \" + name, e);\n\t\t\t}\n\t\t\tthrow new CachedContentException(\"Failed to update cached content: \" + name, e);\n\t\t}\n\t}\n\n\t/**\n\t * Deletes cached content by name.\n\t * @param name the cached content name\n\t * @return true if deleted successfully, false otherwise\n\t */\n\tpublic boolean delete(String name) {\n\t\tAssert.hasText(name, \"Name must not be empty\");\n\n\t\ttry {\n\t\t\tDeleteCachedContentConfig config = DeleteCachedContentConfig.builder().build();\n\t\t\tDeleteCachedContentResponse response = this.caches.delete(name, config);\n\t\t\tif (logger.isDebugEnabled()) {\n\t\t\t\tlogger.debug(\"Deleted cached content: \" + name);\n\t\t\t}\n\t\t\treturn true;","sourceCodeStart":148,"sourceCodeEnd":184,"githubUrl":"https://github.com/spring-projects/spring-ai/blob/98a7beda4f29d80a71c5837eb4053b03a93a46f7/models/spring-ai-google-genai/src/main/java/org/springframework/ai/google/genai/cache/GoogleGenAiCachedContentService.java#L148-L184","documentation":"GoogleGenAiCachedContentService.update(name, request) wraps any exception from the remote cached-content update call (contexts.update / patch) in a CachedContentException. Called internally by extendTtl and refreshExpiration, so TTL-extension failures surface here too.","triggerScenarios":"Calling update() (directly or via extendTtl/refreshExpiration) when the remote update call fails: cached content name does not exist, invalid update fields, insufficient permissions, or network/API errors.","commonSituations":"Trying to extend TTL on cached content that already expired or was deleted, mistyped fully-qualified cached-content resource name, or credentials lacking permission to modify the cache resource.","solutions":["Verify the cached content name exists (call get(name) first) and has not expired","Inspect the chained cause for the underlying API error","Check IAM/permissions on the cache resource","Recreate the cached content if it expired instead of updating"],"exampleFix":"// before\nservice.extendTtl(name, Duration.ofHours(1));\n// after\nif (service.get(name) != null) {\n    service.extendTtl(name, Duration.ofHours(1));\n} else {\n    logger.warn(\"cached content {} missing/expired; recreating\", name);\n}","handlingStrategy":"validation","validationCode":"if (service.get(name) == null) {\n    // recreate instead of update\n} else {\n    service.update(name, request);\n}","typeGuard":null,"tryCatchPattern":"try {\n    service.extendTtl(name, extra);\n} catch (CachedContentException e) {\n    if (service.get(name) == null) {\n        service.create(rebuildRequest()); // expired -> recreate\n    }\n}","preventionTips":["Check existence with get(name) before updating","Refresh TTL at intervals shorter than the cache TTL","Use fully-qualified, exact resource names","Verify permissions to modify the cache resource"],"tags":["google-genai","api","caching","ttl","wrapped-exception"],"backgroundTag":"api-error-response","analyzedSha":"98a7beda4f29d80a71c5837eb4053b03a93a46f7","analyzedAt":"2026-09-11T14:15:49.441Z","contentChangedAt":"2026-09-11T14:15:49.441Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}