LangChain Reference home pageLangChain ReferenceLangChain Reference
  • GitHub
  • Main Docs
Deep Agents
LangChain
LangGraph
Integrations
LangSmith
  • Overview
  • Client
  • AsyncClient
  • Run Helpers
  • Run Trees
  • Evaluation
  • Schemas
  • Utilities
  • Wrappers
  • Anonymizer
  • Testing
  • Expect API
  • Middleware
  • Pytest Plugin
  • Deployment SDK
⌘I

LangChain Assistant

Ask a question to get started

Enter to send•Shift+Enter new line

Menu

OverviewClientAsyncClientRun HelpersRun TreesEvaluationSchemasUtilitiesWrappersAnonymizerTestingExpect APIMiddlewarePytest PluginDeployment SDK
Language
Theme
Pythonlangsmithprompt_cache
Moduleā—Since v0.7

prompt_cache

Prompt caching module for LangSmith SDK.

This module provides thread-safe LRU caches with background refresh for prompt caching. Includes both sync and async implementations.

Attributes

attribute
logger
attribute
DEFAULT_PROMPT_CACHE_TTL_SECONDS: int
attribute
DEFAULT_PROMPT_CACHE_MAX_SIZE: int
attribute
DEFAULT_PROMPT_CACHE_REFRESH_INTERVAL_SECONDS: int
attribute
prompt_cache_singleton
attribute
async_prompt_cache_singleton

Functions

function
configure_global_prompt_cache
function
configure_global_async_prompt_cache

Classes

View source on GitHub
class
CacheEntry
class
CacheMetrics
class
PromptCache
class
AsyncPromptCache
class
Cache
class
AsyncCache

Configure the global prompt cache.

This should be called before any cache instances are created or used.

Configure the global prompt cache.

This should be called before any cache instances are created or used.

A single cache entry with metadata for TTL tracking.

Cache performance metrics.

Thread-safe LRU cache with background thread refresh.

For use with the synchronous Client.

Features:

  • In-memory LRU cache with configurable max size
  • Background thread for refreshing stale entries
  • Stale-while-revalidate: returns stale data while refresh happens
  • Thread-safe for concurrent access

Thread-safe LRU cache with asyncio task refresh.

For use with the asynchronous AsyncClient.

Features:

  • In-memory LRU cache with configurable max size
  • Asyncio task for refreshing stale entries
  • Stale-while-revalidate: returns stale data while refresh happens
  • Thread-safe for concurrent access

Deprecated alias for PromptCache. Use PromptCache instead.

Deprecated alias for AsyncPromptCache. Use AsyncPromptCache instead.