InMemoryCache Class — langchain Architecture
Architecture documentation for the InMemoryCache class in test_cache.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD 529e5351_16cb_1794_4aeb_22c5d8662e85["InMemoryCache"] 374b7b0c_f4fd_ba00_b93d_1a3cbb3b05cb["BaseCache"] 529e5351_16cb_1794_4aeb_22c5d8662e85 -->|extends| 374b7b0c_f4fd_ba00_b93d_1a3cbb3b05cb 60cdbc8d_9b5c_7e23_99e6_15dcd889c805["test_cache.py"] 529e5351_16cb_1794_4aeb_22c5d8662e85 -->|defined in| 60cdbc8d_9b5c_7e23_99e6_15dcd889c805 23971525_1dd2_c01c_54aa_960de3cb5a61["__init__()"] 529e5351_16cb_1794_4aeb_22c5d8662e85 -->|method| 23971525_1dd2_c01c_54aa_960de3cb5a61 e89fc862_11ab_4610_7cc9_434f08faa451["lookup()"] 529e5351_16cb_1794_4aeb_22c5d8662e85 -->|method| e89fc862_11ab_4610_7cc9_434f08faa451 c2a7293d_50d8_58a9_0b47_29bcb93bad8e["update()"] 529e5351_16cb_1794_4aeb_22c5d8662e85 -->|method| c2a7293d_50d8_58a9_0b47_29bcb93bad8e 4008d2b6_eb90_dd51_09cc_e52fafaef92f["clear()"] 529e5351_16cb_1794_4aeb_22c5d8662e85 -->|method| 4008d2b6_eb90_dd51_09cc_e52fafaef92f
Relationship Graph
Source Code
libs/core/tests/unit_tests/language_models/chat_models/test_cache.py lines 21–39
class InMemoryCache(BaseCache):
"""In-memory cache used for testing purposes."""
def __init__(self) -> None:
"""Initialize with empty cache."""
self._cache: dict[tuple[str, str], RETURN_VAL_TYPE] = {}
def lookup(self, prompt: str, llm_string: str) -> RETURN_VAL_TYPE | None:
"""Look up based on `prompt` and `llm_string`."""
return self._cache.get((prompt, llm_string), None)
def update(self, prompt: str, llm_string: str, return_val: RETURN_VAL_TYPE) -> None:
"""Update cache based on `prompt` and `llm_string`."""
self._cache[prompt, llm_string] = return_val
@override
def clear(self, **kwargs: Any) -> None:
"""Clear cache."""
self._cache = {}
Extends
Source
Frequently Asked Questions
What is the InMemoryCache class?
InMemoryCache is a class in the langchain codebase, defined in libs/core/tests/unit_tests/language_models/chat_models/test_cache.py.
Where is InMemoryCache defined?
InMemoryCache is defined in libs/core/tests/unit_tests/language_models/chat_models/test_cache.py at line 21.
What does InMemoryCache extend?
InMemoryCache extends BaseCache.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free