Method Signature
Parameters
ListCachedContentsConfig
Optional configuration for the list request.Available options:
page_size: Number of caches per pagepage_token: Token for fetching a specific pagehttp_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 namemodel: Associated modeldisplay_name: Human-readable namecreate_time: Creation timestampupdate_time: Last updateexpire_time: Expiration timestampusage_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
API Availability
This method is available in both Gemini API and Vertex AI.
Related Methods
- caches.create - Create a new cache
- caches.get - Get cache metadata
- caches.update - Update cache expiration
- caches.delete - Delete a cache