Skip to main content
Updates the expiration settings of a cached content resource. This allows you to extend the lifetime of a cache without recreating it.

Method Signature

Parameters

string
required
The cached content resource name to update.Format: "cachedContents/abc123"
UpdateCachedContentConfig
Configuration for the update.Available options:
  • ttl: New time-to-live duration (e.g., "3600s" for 1 hour)
  • expire_time: New specific expiration timestamp
Specify either ttl OR expire_time, not both.

Returns

CachedContent
The updated CachedContent object with the new expiration time.Contains:
  • name: Resource name
  • expire_time: Updated expiration timestamp
  • update_time: When the update occurred
  • All other cache metadata

Examples

Extend Cache by Duration

Set Specific Expiration Time

Extend Cache for 24 Hours

Conditional Extension

Extend Multiple Caches

Async Update

Extend Cache Before Heavy Usage

Set Cache to Expire at End of Day

Keep-Alive Pattern

Update and Verify

Extend with Maximum TTL

Important Notes

  • Only expiration settings can be updated
  • The cached content itself (documents, context, etc.) cannot be modified
  • To change cached content, you must create a new cache
  • Updates reset the update_time but not create_time
You cannot update:
  • The cached content/documents
  • The model
  • System instructions
  • Tools configuration
  • Display name
To modify these, create a new cache with caches.create().

TTL Limits

Different APIs may have different maximum TTL limits:
  • Gemini API: Check current documentation for limits
  • Vertex AI: May have different limits
Attempting to set a TTL beyond the maximum will result in an error.

Error Handling

API Availability

This method is available in both Gemini API and Vertex AI.