Skip to content

Archive

Functools

1 articles
Python 02 Sep 2026 4 min read

Cache Pure Work in Python with functools.cache and lru_cache

Caching can turn repeated expensive work into a dictionary lookup, but it can also return stale data or grow memory without bound. Python’s functools module provides two convenient memoization decorators: lru_cache and cache. functools.cache has been available since Python 3.9. It is effectively an unbounded memoization cache. lru_cache adds a configurable size limit and eviction behavior. Cache functions, not arbitrary side effects Memoization works best when a function behaves like a pure function: the result depends only on its arguments.