MCPcopy Index your code
hub / github.com/codeaashu/claude-code / should1hCacheTTL

Function should1hCacheTTL

src/services/api/claude.ts:393–434  ·  view source on GitHub ↗

* Determines if 1h TTL should be used for prompt caching. * * Only applied when: * 1. User is eligible (ant or subscriber within rate limits) * 2. The query source matches a pattern in the GrowthBook allowlist * * GrowthBook config shape: { allowlist: string[] } * Patterns support trailing '*

(querySource?: QuerySource)

Source from the content-addressed store, hash-verified

391 * TTLs when GrowthBook's disk cache updates mid-request.
392 */
393function should1hCacheTTL(querySource?: QuerySource): boolean {
394 // 3P Bedrock users get 1h TTL when opted in via env var — they manage their own billing
395 // No GrowthBook gating needed since 3P users don't have GrowthBook configured
396 if (
397 getAPIProvider() === 'bedrock' &&
398 isEnvTruthy(process.env.ENABLE_PROMPT_CACHING_1H_BEDROCK)
399 ) {
400 return true
401 }
402
403 // Latch eligibility in bootstrap state for session stability — prevents
404 // mid-session overage flips from changing the cache_control TTL, which
405 // would bust the server-side prompt cache (~20K tokens per flip).
406 let userEligible = getPromptCache1hEligible()
407 if (userEligible === null) {
408 userEligible =
409 process.env.USER_TYPE === 'ant' ||
410 (isClaudeAISubscriber() && !currentLimits.isUsingOverage)
411 setPromptCache1hEligible(userEligible)
412 }
413 if (!userEligible) return false
414
415 // Cache allowlist in bootstrap state for session stability — prevents mixed
416 // TTLs when GrowthBook's disk cache updates mid-request
417 let allowlist = getPromptCache1hAllowlist()
418 if (allowlist === null) {
419 const config = getFeatureValue_CACHED_MAY_BE_STALE<{
420 allowlist?: string[]
421 }>('tengu_prompt_cache_1h_config', {})
422 allowlist = config.allowlist ?? []
423 setPromptCache1hAllowlist(allowlist)
424 }
425
426 return (
427 querySource !== undefined &&
428 allowlist.some(pattern =>
429 pattern.endsWith('*')
430 ? querySource.startsWith(pattern.slice(0, -1))
431 : querySource === pattern,
432 )
433 )
434}
435
436/**
437 * Configure effort parameters for API request.

Callers 1

getCacheControlFunction · 0.85

Calls 8

getAPIProviderFunction · 0.85
isEnvTruthyFunction · 0.85
getPromptCache1hEligibleFunction · 0.85
setPromptCache1hEligibleFunction · 0.85
isClaudeAISubscriberFunction · 0.50

Tested by

no test coverage detected