[PR #2786] Add node write cache support and implement for Postgres checkpointer #2919

Closed
opened 2026-02-20 17:47:47 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/langchain-ai/langgraph/pull/2786

State: closed
Merged: No


Summary:

Added caching support for individual nodes, and implemented in Postgres. Added tests for caching.

Details:

  • Added cache parameter to add_node method in langgraph/graph/state.py. Takes a CachePolicy object.
  • Implemented CachePolicy type in langgraph/types.py with two parameters: required cache_key and optional ttl (in seconds). cache_key is a function that generates a hash based on (1) the current state of the graph during runtime and (2) the config.
  • Implemented task_id based on the cache_key function for nodes that have a defined CachePolicy, in langgraph/pregel/algo.py. cache_key will generate a hash based on the current input and config.
  • Implemented pending writes retrieval for nodes that have a defined CachePolicy in langgraph/pregel/loop.py.
  • Added get_writes(task_id, ttl) method to base checkpointer in checkpoint/langgraph/checkpoint/base/__init__.py.
  • Implemented get_writes() method for Postgres checkpointer in checkpoint-postgres/langgraph/checkpoint/postgres/__init__.py.
  • Added basic tests in langgraph/tests/test_cache.py.
**Original Pull Request:** https://github.com/langchain-ai/langgraph/pull/2786 **State:** closed **Merged:** No --- ### Summary: Added caching support for individual nodes, and implemented in Postgres. Added tests for caching. ### Details: - Added `cache` parameter to `add_node` method in `langgraph/graph/state.py`. Takes a `CachePolicy` object. - Implemented `CachePolicy` type in `langgraph/types.py` with two parameters: required `cache_key` and optional `ttl` (in seconds). `cache_key` is a function that generates a hash based on (1) the current state of the graph during runtime and (2) the config. - Implemented `task_id` based on the `cache_key` function for nodes that have a defined `CachePolicy`, in `langgraph/pregel/algo.py`. `cache_key` will generate a hash based on the current input and config. - Implemented pending writes retrieval for nodes that have a defined `CachePolicy` in `langgraph/pregel/loop.py`. - Added `get_writes(task_id, ttl)` method to base checkpointer in `checkpoint/langgraph/checkpoint/base/__init__.py`. - Implemented `get_writes()` method for Postgres checkpointer in `checkpoint-postgres/langgraph/checkpoint/postgres/__init__.py`. - Added basic tests in `langgraph/tests/test_cache.py`.
yindo added the pull-request label 2026-02-20 17:47:47 -05:00
yindo closed this issue 2026-02-20 17:47:47 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langchain-ai/langgraph#2919