Method Signature
Parameters
string
required
The cached content resource name to delete.Format:
"cachedContents/abc123"DeleteCachedContentConfig
Optional configuration for the request.Available options:
http_options: Custom HTTP request options
Returns
DeleteCachedContentResponse
A response object confirming the deletion.Contains:
sdk_http_response: HTTP response metadata
Examples
Delete Cache
Delete After Use
Delete Multiple Caches
Delete Old Caches
Delete All Caches
Async Delete
Delete with Verification
Context Manager Pattern
Delete Expiring Caches
Cleanup by Display Name Pattern
Batch Delete with Results
Delete Cache After Session
Cost Optimization
Deleting caches when no longer needed:
- Stops billing for cached token storage
- Frees up cache quota
- Prevents accidental use of outdated cached content
Error Handling
Important Notes
Caches are automatically deleted when they expire, so manual deletion is optional. However, deleting unused caches early can reduce costs.
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.list - List all caches