Last reviewed: November 14, 2026 (Asia/Shanghai); sources fetched November 13 UTC.

Direct answer

Control Gemini explicit cache storage costs by budgeting the number of cached tokens multiplied by their permitted storage duration. Give each cache an owner, an explicit expiry, and a fixed workload deadline. Charge every extension against the same allowance, then read back the resulting expiry before recording the change as verified.

Google’s generateContent context-caching guide says explicit caches default to a one-hour time to live when TTL is omitted. It says caching cost depends on input token size and how long those tokens persist. Budget the remaining lifetime even when a workload has stopped generating answers.

Use cached-input counters to evaluate reuse, and resource metadata to govern lifetime. They answer different financial questions.

Who this is for

This workflow serves platform engineers and AI budget owners managing explicit CachedContent resources through the Gemini API’s generateContent path. The guide currently marks explicit caching as Beta under v1beta and excludes Gemini 4 models. Verify support for the exact model and API before implementing this policy.

The calculations and admission rules below are operating recommendations. No authenticated cache operation, model generation, or billing experiment was performed for this article.

Key takeaways

  • Forecast storage with provider-reported cached tokens and the remaining scheduled lifetime.
  • Keep storage, cached-input reads, other input, and output charges on separate lines.
  • Give creation and renewal one shared workload allowance and a fixed latest expiry.
  • Follow every inventory page; a short page does not establish completion.
  • Preserve source material and configuration needed to recreate a cache.
  • Verify resource state and billing separately after expiration or deletion.

Contract details to verify

Before approving a cache budget, record the following contract facts for the selected workload. Use the linked official references to establish provider behavior, then verify the actual resource and account settings.

Contract detailEvidence to captureBudget decision
Model and API eligibilityExact model, API version, and explicit-caching support from the generateContent guideAdmit only a supported combination
Storage pricingAccount-approved storage terms, currency, billing units, and effective datesNormalize the rate before pricing each lifetime interval
Inventory completenessResource scope, every pagination token, total token count, and returned expiry from Google’s public API definitionsKeep fleet exposure unverified if coverage is incomplete
Expiration changesThe service definition’s expiration-only contract and the resource definition’s returned absolute expiryCount an extension against the shared allowance and fixed deadline
Early retirementExact resource identity, delete outcome, and subsequent metadata observationVerify resource state before reducing the outstanding commitment

Keep account-specific billing terms and the reconstruction source manifest with this record. The public references define the API and pricing dimensions; the workload’s owner, allowance, latest expiry, and recovery requirements are application policy.

Calculate the remaining token-hours

Google’s public CachedContent API definition defines model, create_time, update_time, expire_time, and usage_metadata.total_token_count. Field names here follow that Protocol Buffers definition; check the corresponding JSON or SDK names in your client. Use the resource’s total token count for its storage forecast. A generation’s cached-input usage measures that request’s reuse; it is not a fleet inventory.

For an observation time t, calculate:

remaining_hours_i = max(0, (expire_time_i - t) in seconds) / 3600
remaining_token_hours_i = total_token_count_i * remaining_hours_i
forecast_storage_i = (remaining_token_hours_i / 1,000,000) * rate_i
fleet_forecast = sum(forecast_storage_i)

Here, rate_i is the account-approved storage rate normalized to currency per million token-hours. Confirm that a linear token-duration calculation fits the applicable terms before using this equation; include any other contractual charges separately. Preserve the pricing observation time and effective dates. If a lifetime crosses a scheduled rate change, split it into intervals and price each interval separately.

This forecasts remaining scheduled exposure under unchanged expirations. It excludes storage already incurred and all generation charges. It also assumes the selected pricing terms apply to the account; billing evidence settles actual cost.

Consider twelve fictional caches, each holding 200,000 tokens. All remain available for the same period:

Remaining lifetime per cacheFleet tokensRemaining token-hoursForecast at rate R per million token-hours
24 hours2,400,00057,600,00057.6 × R
90 minutes2,400,0003,600,0003.6 × R

The first schedule has sixteen times the storage exposure. These are hypothetical schedules and arithmetic, not a measured saving or a Google price quote. Shorter retention is useful only if it still serves the workload’s reuse window.

Use the site’s prompt-caching break-even method to judge whether reuse justifies caching at all. Add this storage forecast to that decision, including replacement caches and their actual request costs.

Build a complete metadata inventory

Collect each authorized project or credential scope separately. Google’s public CacheService API definition accepts page_size and page_token, may return fewer objects than requested, and supplies next_page_token when more pages remain. Continue until that token is absent. Keep the other pagination parameters unchanged, as the definition requires.

If any page fails, mark coverage incomplete. Do not treat the partial total as the fleet’s complete budget exposure or use it to authorize automatic cleanup. Listing over time is also not an atomic snapshot: re-read a selected cache immediately before changing it.

Maintain an application-owned record alongside provider metadata:

FieldPurpose
Scope alias and resource nameIdentify the exact cache without relying on its display name
Model and total token countSelect the approved rate and storage quantity
Creation, observation, and expiry timesExplain the forecast interval
Owner and workload revisionConnect retention to an accountable use
Fixed latest expiry and renewal allowanceBound future extensions
Source manifest and configuration referenceSupport reconstruction
Operation identity and verification statePreserve uncertain changes for reconciliation

Track meaningful application use in your own workload records. The resource definition describes update_time as the last cache update; it does not establish the last useful business interaction. A renewal process can make that timestamp recent even when the application no longer needs the context.

The resource definition marks cached contents and system_instruction as input-only and immutable. Keep approved source files, instructions, and model configuration elsewhere for the required recovery period. An inventory row alone cannot rebuild the resource.

Put renewals through budget admission

Before creation, assign a maximum context size, an initial lifetime, a latest permitted expiry, and an aggregate workload allowance. Reserve conservatively before the request, then reconcile against the returned token count and expiry. An estimate with no verified upper bound supports a forecast; it cannot establish a hard financial ceiling.

Renewals must preserve the workload’s original deadline. A background job that repeatedly asks for another hour can keep extending a resource after the useful work has ended. Make the deadline an application policy value that ordinary refresh jobs cannot move.

For an existing cache, the decision can follow this pseudocode:

candidate_expiry = min(requested_expiry, workload.latest_expire_at)
reject if candidate_expiry <= current_time
extension_hours = max(0, candidate_expiry - current_expiry) / 3600
extension_token_hours = total_token_count * extension_hours
authorize and reserve the extension in the shared workload budget
submit the approved expiry change
read back expiry; reconcile the reservation or retain unresolved state

Treat timestamp subtraction above as seconds. Price the extension using its applicable rate intervals. Serialize admission and reservation in a shared authority so concurrent workers cannot each spend the same remaining allowance. Serialize lifecycle writes for each cache too, including retirement, so an older renewal cannot overwrite a newer decision. Keep the previous commitment counted until a reduction is verified.

The CacheService definition allows only expiration to change. The CachedContent definition accepts either input-only ttl or an absolute UTC expire_time, with expire_time always provided on output. Choose one representation per request. An absolute expiry makes the fixed deadline easier to inspect; check your client’s field naming.

If an update times out, preserve its operation identity and inspect current metadata before sending another relative TTL. A repeated relative duration can move the desired end time. If creation is uncertain, reconcile the operation record and inventory before creating a replacement; unresolved evidence is not proof that no cache exists.

Retire the cache and preserve a recovery path

Choose an explicit expiry at creation even when the one-hour default appears suitable. Read back the provider’s actual expiry and compare it with policy. For an early retirement, Google’s CacheService definition documents deletion of a specific CachedContent resource.

Coordinate retirement with consumers and renewal workers. Stop new references, prevent later extensions, and let the owner decide how already-dispatched requests should be handled. Re-read the exact resource before the change, then verify its resulting availability through metadata operations.

Record the request outcome, subsequent resource observation, and eventual billing reconciliation separately. Permission failures and timeouts leave state unresolved. A successful deletion is not an invoice adjustment, and an absent resource does not quantify a refund or the billed storage interval.

If the application still needs the context after retirement, recreate it from the retained sources and configuration under a new approved budget. Preserve the new resource identity and verify consumers use it. Recreation can introduce new storage and request costs, so a shorter TTL alone does not establish a lower total workload cost.

For teams also managing retrieval stores, the guide to file-search vector-store expiration covers their activity-based contracts. Check each resource’s actual expiration semantics before sharing automation between them.

Verification before rollout

Start with local policy checks and metadata-only inventory. Then use one approved disposable cache to check the provider interaction. The following are proposed acceptance checks, not reported results:

ScenarioRequired observation
First list page is shorter than requested and has a next tokenCollector continues and includes later resources
A later page failsCoverage is incomplete; fleet approval and cleanup stop
Two workers request extensions togetherCombined reservations stay within the shared allowance
Requested expiry exceeds the workload deadlinePolicy rejects or clips it before the API call
Update response is lostReadback resolves the actual expiry before another change
Cache expires or is removedConsumers follow the planned recovery path; billing remains a separate check

Compare the observed token count, returned expiry, and approved pricing terms with the forecast. Over a defined billing interval, reconcile storage separately from cached-input and output charges. Explain gaps such as incomplete coverage, replacements, extensions, or a rate change before reporting savings.

Failure modes

A high cache-hit rate hides idle storage. Successful reuse earlier in the day does not justify retention overnight. Review the remaining token-hours against future demand.

Every worker receives the entire allowance. Parallel renewals expand exposure. Use shared admission or disjoint allocations whose sum fits the workload budget.

A recent update is treated as recent business use. The renewal worker keeps its own evidence fresh. Use application use records to justify another extension.

Inventory success is declared after one page. Missing resources make both the forecast and cleanup decision incomplete. Verify pagination coverage explicitly.

Recreation erases the expected benefit. Frequent expiry creates replacement work and service disruption. Evaluate total workload cost and recovery behavior over a representative interval.

Sources checked

Three primary Google documents returned HTTP 200 during live research on November 13 UTC, November 14 in Asia/Shanghai:

These currently served official references support an evergreen operating task. Retrieval establishes current availability, not a new release date. Recheck support and pricing for the chosen model before approving a creation or extension.

FAQ

Does a cache with no new requests have zero cost?

Include its remaining storage lifetime in the forecast. Google’s guide relates caching cost to token size and persistence duration; lack of new generations does not establish a zero storage budget.

Can one successful list request prove the inventory is complete?

Only if there is no next-page token for that scope. Other authorized scopes still need their own coverage checks.

Should every request extend the cache?

Only when workload policy and the shared budget permit it. Keep the latest expiry fixed and require a new owner decision to extend the workload itself.

Reader next step

Inventory one workload without changing its caches. Calculate its remaining token-hours, attach owners and reconstruction references, and choose a fixed latest expiry. Test the renewal rule against concurrent requests and a lost update response before approving one bounded provider canary.