Variable: cache
@providerprotocol/ai / google / cache
Variable: cache
Section titled “Variable: cache”
constcache:object
Defined in: src/providers/google/cache.ts:452
Cache utilities namespace.
Provides functions for creating and managing Google Gemini cached content entries. Use cached content to reduce costs and latency when repeatedly sending the same context (system instructions, large documents, etc.) across multiple requests.
Type Declaration
Section titled “Type Declaration”create()
Section titled “create()”create: (
options) =>Promise<GoogleCacheResponse>
Creates a new cached content entry.
Caches can contain system instructions, conversation content, and tool declarations that are reused across multiple requests. This reduces token costs and processing time for repeated context.
Parameters
Section titled “Parameters”options
Section titled “options”Cache creation options
Returns
Section titled “Returns”Promise<GoogleCacheResponse>
The created cache entry with its name/ID for use in requests
Example
Section titled “Example”import { google } from '@anthropic/provider-protocol';
// Create a cache with system instruction and large contextconst cache = await google.cache.create({ apiKey: process.env.GOOGLE_API_KEY, model: 'gemini-3-flash-preview', displayName: 'Code Review Context', systemInstruction: 'You are an expert code reviewer...', contents: [ { role: 'user', parts: [{ text: largeCodebaseContent }] } ], ttl: '3600s', // 1 hour});
// Use the cache in subsequent requestsconst response = await model.complete({ messages: [userMessage('Review this function')], params: { cachedContent: cache.name },});delete()
Section titled “delete()”delete: (
name,apiKey,config?,signal?) =>Promise<void> =deleteCache
Deletes a cached content entry.
Parameters
Section titled “Parameters”string
The cache name (format: “cachedContents/{id}“)
apiKey
Section titled “apiKey”string
API key for authentication
config?
Section titled “config?”Provider configuration (timeout, retry strategy, custom fetch)
signal?
Section titled “signal?”AbortSignal
Abort signal for cancellation
Returns
Section titled “Returns”Promise<void>
Example
Section titled “Example”await google.cache.delete('cachedContents/abc123', apiKey);get: (
name,apiKey,config?,signal?) =>Promise<GoogleCacheResponse>
Retrieves a cached content entry by name.
Parameters
Section titled “Parameters”string
The cache name (format: “cachedContents/{id}“)
apiKey
Section titled “apiKey”string
API key for authentication
config?
Section titled “config?”Provider configuration (timeout, retry strategy, custom fetch)
signal?
Section titled “signal?”AbortSignal
Abort signal for cancellation
Returns
Section titled “Returns”Promise<GoogleCacheResponse>
The cache entry details
Example
Section titled “Example”const cache = await google.cache.get('cachedContents/abc123', apiKey);console.log(`Cache expires at: ${cache.expireTime}`);list()
Section titled “list()”list: (
options) =>Promise<GoogleCacheListResponse>
Lists all cached content entries.
Parameters
Section titled “Parameters”options
Section titled “options”List options including API key and pagination
Returns
Section titled “Returns”Promise<GoogleCacheListResponse>
Array of cache entries and optional next page token
Example
Section titled “Example”const { cachedContents, nextPageToken } = await google.cache.list({ apiKey: process.env.GOOGLE_API_KEY, pageSize: 10,});
for (const cache of cachedContents ?? []) { console.log(`${cache.displayName}: ${cache.name}`);}update()
Section titled “update()”update: (
name,updateRequest,apiKey,config?,signal?) =>Promise<GoogleCacheResponse>
Updates a cached content entry’s expiration time.
Only the expiration time can be updated; all other fields (contents, systemInstruction, tools) are immutable after creation.
Parameters
Section titled “Parameters”string
The cache name (format: “cachedContents/{id}“)
updateRequest
Section titled “updateRequest”apiKey
Section titled “apiKey”string
API key for authentication
config?
Section titled “config?”Provider configuration (timeout, retry strategy, custom fetch)
signal?
Section titled “signal?”AbortSignal
Abort signal for cancellation
Returns
Section titled “Returns”Promise<GoogleCacheResponse>
The updated cache entry
Example
Section titled “Example”// Extend cache expiration by 2 hoursconst updated = await google.cache.update( 'cachedContents/abc123', { ttl: '7200s' }, apiKey);Example
Section titled “Example”import { google } from '@anthropic/provider-protocol';
// Create a cacheconst cache = await google.cache.create({ apiKey: process.env.GOOGLE_API_KEY, model: 'gemini-3-flash-preview', systemInstruction: 'You are an expert assistant...', contents: [{ role: 'user', parts: [{ text: largeDocument }] }], ttl: '3600s',});
// Use cache.name in requests via params.cachedContentconst response = await model.complete({ messages: [userMessage('Summarize the document')], params: { cachedContent: cache.name },});
// Manage cachesconst caches = await google.cache.list({ apiKey });await google.cache.update(cache.name, { ttl: '7200s' }, apiKey);await google.cache.delete(cache.name, apiKey);