What does it do?
Cachetools gives Python programs smart, size-limited memory banks for storing the results of expensive calculations or slow lookups, so the same request doesn’t get repeated from scratch every time. It offers different strategies for what to forget when the cache fills up: least-recently-used, least-frequently-used, or simple time-based expiration. Developers typically use it as a decorator wrapping a function, so calling that function again with the same input instantly returns the saved answer instead of redoing the work. It’s the kind of tool that speeds up software without changing what it actually does.
See it in action
This remembers the result of a slow calculation, so asking for the same answer a second time returns the saved result instantly instead of redoing the work.
from cachetools import cached, LRUCache
cache = LRUCache(maxsize=100)
@cached(cache)
def slow_square(n):
print("Computing the slow way...")
return n * n
slow_square(4)
slow_square(4)
Why would a non-developer care?
Caching is one of the biggest reasons modern software feels fast: web pages and services constantly reuse recent answers instead of recalculating everything from zero. When a website loads instantly the second time you visit a page, some version of this exact idea is very likely at work.
Real-world examples
It’s a common building block in web backends and data pipelines that repeatedly ask the same expensive question, like looking up a user’s account details or recalculating a report. Bigger platforms build far more elaborate caching systems like Redis for scale, but cachetools solves the same core problem for a single running program with no extra infrastructure.
Who uses it
Backend and data engineers optimizing Python code that repeats slow lookups or calculations more often than necessary.
How it compares to alternatives
Python’s standard library has a basic built-in cache decorator, functools.lru_cache, but cachetools offers considerably more flexibility and multiple eviction strategies the built-in version doesn’t cleanly handle.