Home / Function/ test_can_swap_caches() — langchain Function Reference

test_can_swap_caches() — langchain Function Reference

Architecture documentation for the test_can_swap_caches() function in test_cache.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  81c1b4f4_1a50_8202_569c_78094835a636["test_can_swap_caches()"]
  51f634bf_713d_3f19_d694_5c6ef3e59c57["test_cache.py"]
  81c1b4f4_1a50_8202_569c_78094835a636 -->|defined in| 51f634bf_713d_3f19_d694_5c6ef3e59c57
  style 81c1b4f4_1a50_8202_569c_78094835a636 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/core/tests/unit_tests/language_models/chat_models/test_cache.py lines 277–295

async def test_can_swap_caches() -> None:
    """Test that we can use a different cache object.

    This test verifies that when we fetch the llm_string representation
    of the chat model, we can swap the cache object and still get the same
    result.
    """
    cache = InMemoryCache()
    chat_model = CustomChat(cache=cache, messages=iter(["hello"]))
    result = await chat_model.ainvoke("foo")
    assert result.content == "hello"

    new_cache = InMemoryCache()
    new_cache._cache = cache._cache.copy()

    # Confirm that we get a cache hit!
    chat_model = CustomChat(cache=new_cache, messages=iter(["goodbye"]))
    result = await chat_model.ainvoke("foo")
    assert result.content == "hello"

Subdomains

Frequently Asked Questions

What does test_can_swap_caches() do?
test_can_swap_caches() is a function in the langchain codebase, defined in libs/core/tests/unit_tests/language_models/chat_models/test_cache.py.
Where is test_can_swap_caches() defined?
test_can_swap_caches() is defined in libs/core/tests/unit_tests/language_models/chat_models/test_cache.py at line 277.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free