Toggle Menu
Prev Up Next

# `langchain_community.cache`.InMemoryCache

class langchain_community.cache.InMemoryCache

  Cache that stores things in memory.

  Initialize with empty cache.

  Methods

  `__init__`() | Initialize with empty cache.
  `aclear`(**kwargs) | Clear cache.
  `alookup`(prompt, llm_string) | Look up based on prompt and llm_string.
  `aupdate`(prompt, llm_string, return_val) | Update cache based on prompt and llm_string.
  `clear`(**kwargs) | Clear cache.
  `lookup`(prompt, llm_string) | Look up based on prompt and llm_string.
  `update`(prompt, llm_string, return_val) | Update cache based on prompt and llm_string.

  __init__() → None

    Initialize with empty cache.

    Return type

      None

  async aclear(**kwargs: Any) → None

    Clear cache.

    Parameters

      kwargs (Any) –

    Return type

      None

  async alookup(prompt: str, llm_string: str) → Optional[Sequence[Generation]]

    Look up based on prompt and llm_string.

    Parameters

      - prompt (str) –

      - llm_string (str) –

    Return type

      Optional[Sequence[Generation]]

  async aupdate(prompt: str, llm_string: str, return_val: Sequence[Generation]) → None

    Update cache based on prompt and llm_string.

    Parameters

      - prompt (str) –

      - llm_string (str) –

      - return_val (Sequence[Generation]) –

    Return type

      None

  clear(**kwargs: Any) → None

    Clear cache.

    Parameters

      kwargs (Any) –

    Return type

      None

  lookup(prompt: str, llm_string: str) → Optional[Sequence[Generation]]

    Look up based on prompt and llm_string.

    Parameters

      - prompt (str) –

      - llm_string (str) –

    Return type

      Optional[Sequence[Generation]]

  update(prompt: str, llm_string: str, return_val: Sequence[Generation]) → None

    Update cache based on prompt and llm_string.

    Parameters

      - prompt (str) –

      - llm_string (str) –

      - return_val (Sequence[Generation]) –

    Return type

      None

# Examples using InMemoryCache

- <!– ruff: noqa: F821 –>

- To make the caching really obvious, lets use a slower model.