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
  • RemoteGraph
⌘I

LangChain Assistant

Ask a question to get started

Enter to send•Shift+Enter new line

Menu

OverviewClientAsyncClientRun HelpersRun TreesEvaluationSchemasUtilitiesWrappersAnonymizerTestingExpect APIMiddlewarePytest PluginDeployment SDKRemoteGraph
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

Configure the global prompt cache.

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

function
configure_global_async_prompt_cache

Configure the global prompt cache.

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

Classes

class
CacheEntry

A single cache entry with metadata for TTL tracking.

class
CacheMetrics

Cache performance metrics.

class
PromptCache

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
class
AsyncPromptCache

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
class
Cache

Deprecated alias for PromptCache. Use PromptCache instead.

class
AsyncCache

Deprecated alias for AsyncPromptCache. Use AsyncPromptCache instead.

View source on GitHub