Skip to content

Variable: cache

@providerprotocol/ai


@providerprotocol/ai / google / cache

const cache: 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.

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.

CacheCreateOptions

Cache creation options

Promise<GoogleCacheResponse>

The created cache entry with its name/ID for use in requests

import { google } from '@anthropic/provider-protocol';
// Create a cache with system instruction and large context
const 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 requests
const response = await model.complete({
messages: [userMessage('Review this function')],
params: { cachedContent: cache.name },
});

delete: (name, apiKey, config?, signal?) => Promise<void> = deleteCache

Deletes a cached content entry.

string

The cache name (format: “cachedContents/{id}“)

string

API key for authentication

ProviderConfig

Provider configuration (timeout, retry strategy, custom fetch)

AbortSignal

Abort signal for cancellation

Promise<void>

await google.cache.delete('cachedContents/abc123', apiKey);

get: (name, apiKey, config?, signal?) => Promise<GoogleCacheResponse>

Retrieves a cached content entry by name.

string

The cache name (format: “cachedContents/{id}“)

string

API key for authentication

ProviderConfig

Provider configuration (timeout, retry strategy, custom fetch)

AbortSignal

Abort signal for cancellation

Promise<GoogleCacheResponse>

The cache entry details

const cache = await google.cache.get('cachedContents/abc123', apiKey);
console.log(`Cache expires at: ${cache.expireTime}`);

list: (options) => Promise<GoogleCacheListResponse>

Lists all cached content entries.

CacheListOptions

List options including API key and pagination

Promise<GoogleCacheListResponse>

Array of cache entries and optional next page token

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: (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.

string

The cache name (format: “cachedContents/{id}“)

GoogleCacheUpdateRequest

string

API key for authentication

ProviderConfig

Provider configuration (timeout, retry strategy, custom fetch)

AbortSignal

Abort signal for cancellation

Promise<GoogleCacheResponse>

The updated cache entry

// Extend cache expiration by 2 hours
const updated = await google.cache.update(
'cachedContents/abc123',
{ ttl: '7200s' },
apiKey
);
import { google } from '@anthropic/provider-protocol';
// Create a cache
const 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.cachedContent
const response = await model.complete({
messages: [userMessage('Summarize the document')],
params: { cachedContent: cache.name },
});
// Manage caches
const caches = await google.cache.list({ apiKey });
await google.cache.update(cache.name, { ttl: '7200s' }, apiKey);
await google.cache.delete(cache.name, apiKey);