Skip to main content
Lists all cached content resources. Returns a paginated list of caches.

Method Signature

Parameters

ListCachedContentsConfig
Optional configuration for the list request.Available options:
  • page_size: Number of caches per page
  • page_token: Token for fetching a specific page
  • http_options: Custom HTTP request options

Returns

Pager[CachedContent]
A Pager object that automatically handles pagination.When you iterate over the pager, it automatically fetches additional pages as needed.Each CachedContent contains:
  • name: Resource name
  • model: Associated model
  • display_name: Human-readable name
  • create_time: Creation timestamp
  • update_time: Last update
  • expire_time: Expiration timestamp
  • usage_metadata: Token usage information

Examples

List All Caches

List with Page Size

Count Total Caches

Find Specific Cache

Calculate Total Token Usage

List Caches by Model

Find Expiring Caches

Async List

Export Cache List

Monitor Cache Health

List and Extend Expiring Caches

Cleanup Old Caches

Display Cache Summary

List Caches with Specific Content

Manual Pagination

Pagination

The list() method returns a Pager that automatically handles pagination. You can iterate over it directly without worrying about page tokens.The pager fetches additional pages automatically as you iterate through the results.

Error Handling

Usage Metadata

Each cache includes usage_metadata with:
  • total_token_count: Total tokens stored in the cache
This helps track storage costs and optimize cache usage.

API Availability

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