spring-projects/spring-ai · error · CachedContentException

Failed to update cached content:

Error message

Failed to update cached content: 

What it means

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.

Source

Thrown at models/spring-ai-google-genai/src/main/java/org/springframework/ai/google/genai/cache/GoogleGenAiCachedContentService.java:166

		}

		if (request.getExpireTime() != null) {
			configBuilder.expireTime(request.getExpireTime());
		}

		try {
			UpdateCachedContentConfig config = configBuilder.build();
			CachedContent cachedContent = this.caches.update(name, config);
			if (logger.isDebugEnabled()) {
				logger.debug("Updated cached content: " + name);
			}
			return GoogleGenAiCachedContent.from(cachedContent);
		}
		catch (Exception e) {
			if (logger.isErrorEnabled()) {
				logger.error("Failed to update cached content: " + name, e);
			}
			throw new CachedContentException("Failed to update cached content: " + name, e);
		}
	}

	/**
	 * Deletes cached content by name.
	 * @param name the cached content name
	 * @return true if deleted successfully, false otherwise
	 */
	public boolean delete(String name) {
		Assert.hasText(name, "Name must not be empty");

		try {
			DeleteCachedContentConfig config = DeleteCachedContentConfig.builder().build();
			DeleteCachedContentResponse response = this.caches.delete(name, config);
			if (logger.isDebugEnabled()) {
				logger.debug("Deleted cached content: " + name);
			}
			return true;

View on GitHub (pinned to 98a7beda4f)

Solutions

  1. Verify the cached content name exists (call get(name) first) and has not expired
  2. Inspect the chained cause for the underlying API error
  3. Check IAM/permissions on the cache resource
  4. Recreate the cached content if it expired instead of updating

Example fix

// before
service.extendTtl(name, Duration.ofHours(1));
// after
if (service.get(name) != null) {
    service.extendTtl(name, Duration.ofHours(1));
} else {
    logger.warn("cached content {} missing/expired; recreating", name);
}
Defensive patterns

Strategy: validation

Validate before calling

if (service.get(name) == null) {
    // recreate instead of update
} else {
    service.update(name, request);
}

Try / catch

try {
    service.extendTtl(name, extra);
} catch (CachedContentException e) {
    if (service.get(name) == null) {
        service.create(rebuildRequest()); // expired -> recreate
    }
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of spring-projects/spring-ai@98a7beda4f (2026-09-11). Data as JSON: /api/errors/4589b0eb41b133b7. Report an issue: GitHub.