Support timedelta for CachePolicy.ttl, consistent with TimeoutPolicy

Is your feature request related to a problem?

CachePolicy lets you skip re-executing a node when its inputs haven’t changed, saving latency and cost on expensive tool calls (LLM APIs, web search,etc.).

When configuring how long to cache a result, it’s natural to think “cache this for 2 hours” rather than “cache this for 7200 seconds”. The current API forces a mental conversion that no other policy in LangGraph requires.

CachePolicy.ttl only accepts int (seconds), while TimeoutPolicy already accepts timedelta for its fields. Both policies configure node behavior and live in the same file, there’s no reason they should accept different types.

Current: CachePolicy(ttl=7200)
Desired: CachePolicy(ttl=timedelta(hours=2))

Proposed solution

LangGraph already supports timedelta in TimeoutPolicy, adding it to CachePolicy makes the API consistent and removes a special case users have to remember.

5 line change in libs/langgraph/langgraph/types.py:

ttl: int | timedelta | None = None

def __post_init__(self) -> None:
    if isinstance(self.ttl, timedelta):
        object.__setattr__(self, "ttl", int(self.ttl.total_seconds()))


timedelta is coerced to int at construction time, CacheKey and everything downstream are unaffected. No breaking changes, no new dependencies (timedelta is already imported in the file).

I can open a PR right away if this direction is welcome.

That’s an interesting catch, but it’s better to open this as an issue on the GitHub - langchain-ai/langgraph: Build resilient agents. · GitHub repo itself so maintainers can give you direct feedback there and possibly assign the issue if needed.