Python caching libraries

Updated Nov 2026

Python caching libraries store the result of an expensive call for reuse when a later call has the same inputs. A cache evicts entries by a policy such as least recently used or a time-to-live. These libraries let web apps and data pipelines skip repeated database queries, API calls, and computations.

Popularity

cachetools has the most monthly downloads in this comparison, at 265.5M.

LibraryMonthly downloadsStarsLast releaseLicense
cachetools
280.0M
2.8KNov 2026MIT
redis-py
249.6M
Not on GitHubJul 2026MIT
Joblib
200.3M
4.4KAug 2026BSD-3-Clause
CacheControl
106.6M
Not on GitHubNov 2026Apache-2.0
async-lru
45.0M
Not on GitHubOct 2026MIT
boltons
30.7M
Not on GitHubSep 2026BSD-3-Clause
diskcache
26.6M
2.9KAug 2023Apache-2.0
cachebox
14.3M
Not on GitHubOct 2026MIT
Downloads: PyPI, last thirty days. Stars and releases: GitHub. Amber: no release in over a year.

Libraries and code examples

Provides cache mappings and decorators for function results.

Downloads / mo
280.0M
Stars
2.8K
Last release
8.0.2
License
MIT

Strengths

  • Bounds retained cache values. Set maxsize to control how much the cache retains.
  • Supports custom value sizing. Use getsizeof when the cache budget should count value sizes.

Limitations

  • Shared caches need synchronization. Protect a shared cache with a lock when multiple threads access it.
  • Expired entries can retain memory. Call expire to remove expired entries during read-only use.

Quickstart

From README.rst
$ python3.13 -m pip install cachetools==8.0.2
from cachetools import TTLCache

cache = TTLCache(maxsize=128, ttl=60)
cache["answer"] = 42
print(cache["answer"])

cachetools examples

From open-source projects on GitHub

Provides the Python client for the Redis database and key-value store.

Downloads / mo
249.6M
Last release
8.1.0
License
MIT

Quickstart

From commands.html
$ python3.13 -m pip install redis==8.1.0
import redis

client = redis.Redis(host="localhost", port=6379, decode_responses=True)
client.set("answer", "42")

redis-py examples

From open-source projects on GitHub

Caches function results on the filesystem for reuse with the same arguments.

Downloads / mo
200.3M
Stars
4.4K
Last release
1.6.0
License
BSD-3-Clause

Strengths

  • Caches function results on disk. Reuse computed results through a named filesystem cache.
  • Expires results through validation callbacks. Use expires_after to recompute results after a chosen duration.

Limitations

  • Size limits need explicit cleanup. Call reduce_size to enforce byte, item, or age limits.

Quickstart

From memory_basic_usage.py
$ python3.13 -m pip install joblib==1.6.0
from joblib import Memory

memory = Memory("./cache", verbose=0)

@memory.cache
def square(value):
    return value * value

square(2)

Joblib examples

From open-source projects on GitHub

Adds HTTP caching to requests sessions.

Downloads / mo
106.6M
Last release
0.15.0
License
Apache-2.0

Quickstart

From README.rst
$ python3.13 -m pip install CacheControl==0.15.0
import requests
from cachecontrol import CacheControl

session = CacheControl(requests.session())
response = session.get("https://example.com")

CacheControl examples

From open-source projects on GitHub

Provides an LRU cache for asyncio.

Downloads / mo
45.0M
Last release
2.4.0
License
MIT

Quickstart

From README.rst
$ python3.13 -m pip install async-lru==2.4.0
import asyncio
from async_lru import alru_cache

@alru_cache(maxsize=32)
async def double(value):
    return value * 2

asyncio.run(double(2))

async-lru examples

From open-source projects on GitHub
def _configure_package_metadata_cache(self, _change: object = None) -> None:
    self._fetch_package_metadata = cast(
        "FetchPackageMetadata",
        alru_cache(maxsize=self.package_metadata_cache_size)(
            partial(_fetch_package_metadata, self._httpx_client)
        ),
    )
    self._package_metadata_cache_expires = monotonic() + self.cache_timeout

Provides utilities that complement Python builtins.

Downloads / mo
30.7M
Last release
26.2.0
License
BSD-3-Clause

Quickstart

From cacheutils.html
$ python3.13 -m pip install boltons==26.2.0
from boltons.cacheutils import LRU

cache = LRU(max_size=128)
cache["answer"] = 42
print(cache["answer"])

boltons examples

From open-source projects on GitHub

Provides disk-backed caches using a SQLite database and filesystem storage.

Downloads / mo
26.6M
Stars
2.9K
Last release
5.6.3
License
Apache-2.0

Strengths

  • Shares caches across processes. Use the same cache directory across threads and processes.
  • Expires individual entries. Set an expiration when writing each cache entry.

Limitations

  • Database operations can time out. Handle Timeout or enable retries for supported cache operations.

Quickstart

From api.html
$ python3.13 -m pip install diskcache==5.6.3
from diskcache import Cache

with Cache("./cache") as cache:
    cache.set("answer", 42)

diskcache examples

From open-source projects on GitHub

Provides memoizing caches written in Rust.

Downloads / mo
14.3M
Last release
6.2.10
License
MIT

Quickstart

From README.md
$ python3.13 -m pip install cachebox==6.2.10
import cachebox

cache = cachebox.LRUCache(maxsize=128)
cache["answer"] = 42
print(cache["answer"])

FAQ

cachetools suits in-process caches with LRU, TTL, and other eviction policies. redis-py suits caches shared across processes and servers. diskcache suits caches that must survive a restart on one machine.

redis-py is the Python client for Redis. A cache stores each result under a key with an expiry and reads that key before recomputing.

Redis stores strings and data structures such as hashes, lists, and sorted sets, with optional persistence. Memcached stores plain values in memory only and scales by adding nodes.

The standard library's functools.lru_cache decorator caches a function's results and evicts the least recently used entries. cachetools adds TTL caches, and async-lru covers coroutines.

diskcache stores cache entries in a SQLite database and the filesystem. Entries persist across restarts and can be shared between processes on the same machine.

For coding agents

Found your caching library? Help your agent use it.

Connect Exa so your coding agent can find the library’s documentation, check its API, and look up implementations while you build.

Run in your terminal

claude plugin install exa@claude-plugins-official