Skip to main content

Corto Cache

CI

pip install corto-cache

Source: https://github.com/Bobowski/corto-cache

from corto import memoize

The index name is corto-cache (corto is taken). The import is corto.

Window-TinyLFU memoize for CPython 3.14.

Decorate a function. A hit returns the stored value. A miss runs the function and stores the result if it returns. New keys enter a small LRU window. They enter the main cache only when a frequency sketch says they are hotter than what would be evicted. A scan of unique keys dies in the window. The hot set stays.

from corto import memoize

@memoize(maxsize=1024)
def parse_accept(header: str) -> tuple[str, ...]:
    return tuple(part.strip() for part in header.split(","))

parse_accept.cache_info()    # hits, misses, maxsize, currsize
parse_accept.cache_clear()

cache_info and cache_parameters match functools.lru_cache. After a load run, hits / (hits + misses) tells you if the same keys came back. Near-zero hits: drop the decorator.

When to use this

Use Corto when the key universe is larger than maxsize and traffic also sends one-shot keys. lru_cache evicts whatever was least recent, so a scan can flush a popular entry. Corto keeps the frequent ones.

Use functools.lru_cache when the working set fits and stays. It is the stdlib, a bit cheaper on miss, and has maxsize=None.

Use neither when the function is cheaper than a lookup, or when every key is new. A miss still runs the function; Corto then pays extra to decide admission.

Cache mapping

When the value is not “return of this function” — insert and read in different places — use the same store as a bounded map:

from corto import Cache

cache = Cache(1024)
cache[header] = parsed
parsed = cache.get(header)

pop, setdefault, clear, in, len, hits, and misses are there. There is no public frequency peek.

Contract

  • Keys must be hashable. Equality follows ==.
  • maxsize is a positive int. No unbounded mode, no TTL.
  • Threads may share one wrapper. The lock is always on.
  • memoize drops the lock while the function runs. Two threads may compute the same key; the first store wins.
  • A key or value __del__ must leave that cache unchanged. The mutex is not recursive.
  • After os.fork, make a new cache in the child.
  • Fixed 1% admission window. No hill-climb. No doorkeeper.

Install

CPython 3.14. Wheels cover Linux x86_64 and aarch64 (glibc and musl), macOS (arm64, x86_64), and Windows AMD64. A source build needs a C compiler and Cython.

pip install corto-cache

From a clone:

uv sync
uv run pytest

Numbers

On this machine (CPython 3.14, Apple Silicon), a one-arg hit is next to lru_cache (~70 ns). A Zipf decorator read is faster than Theine and cachebox, and a bit faster than lru_cache on that mix. Hit rate under a scan is the reason to pick Corto, not hit time.

Full tables and how to re-run: benchmarks/README.md.

TinyLFU: https://arxiv.org/pdf/1512.00727
Caffeine W-TinyLFU: https://github.com/ben-manes/caffeine/wiki/Efficiency

Metadata

Release files for corto-cache 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for corto-cache 0.1.1
File Size Uploaded
corto_cache-0.1.1.tar.gz 167.2 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for corto-cache 0.1.1
File
corto_cache-0.1.1-cp314-cp314-win_amd64.whl CPython 3.14 CPython 3.14 Windows x86-64 Details
corto_cache-0.1.1-cp314-cp314-musllinux_1_2_x86_64.whl CPython 3.14 CPython 3.14 Linux musl 1.2+ x86-64 Details
corto_cache-0.1.1-cp314-cp314-musllinux_1_2_aarch64.whl CPython 3.14 CPython 3.14 Linux musl 1.2+ ARM64 Details
corto_cache-0.1.1-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl CPython 3.14 CPython 3.14 Linux glibc 2.17+ x86-64, Linux glibc 2.28+ x86-64 Details
corto_cache-0.1.1-cp314-cp314-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl CPython 3.14 CPython 3.14 Linux glibc 2.17+ ARM64, Linux glibc 2.28+ ARM64 Details
corto_cache-0.1.1-cp314-cp314-macosx_11_0_arm64.whl CPython 3.14 CPython 3.14 macOS 11.0+ ARM64 Details
corto_cache-0.1.1-cp314-cp314-macosx_10_15_x86_64.whl CPython 3.14 CPython 3.14 macOS 10.15+ x86-64 Details

Total release size: 2.4 MB

Release files / corto_cache-0.1.1.tar.gz

Download URL corto_cache-0.1.1.tar.gz
Size 167.2 kB
Tags Source
SHA-256 checksum
How to use checksums
52227db58ae9a9b85d3155b94092cbdea78f17d91e52a4645e8b85d0ad2cf6a4
BLAKE2b-256 checksum
How to use checksums
91fe95f2ff9add0c6ea623d2a1bfddb4a8fc12883c7f79282a872c44f8792a15
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 21, 2026.

Transparency log

Release files / corto_cache-0.1.1-cp314-cp314-win_amd64.whl

Download URL corto_cache-0.1.1-cp314-cp314-win_amd64.whl
Size 65.2 kB
Tags CPython 3.14 Windows x86-64
SHA-256 checksum
How to use checksums
ed5b62e6a092e05ba9de9d715693ee8cc2d39e00b7a903ae48e2cb1c3e0aa8fc
BLAKE2b-256 checksum
How to use checksums
a2d9034333eba0e7b077c144602bc22aa244472055619a46c1a20f7bf49eda2f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 21, 2026.

Transparency log

Release files / corto_cache-0.1.1-cp314-cp314-musllinux_1_2_x86_64.whl

Download URL corto_cache-0.1.1-cp314-cp314-musllinux_1_2_x86_64.whl
Size 491.2 kB
Tags CPython 3.14 Linux musl 1.2+ x86-64
SHA-256 checksum
How to use checksums
d71d1575fa41c8bdbc4ced6e74a3872a2c0818440fe6204a025996bb42db1627
BLAKE2b-256 checksum
How to use checksums
5d2da8c02cec0db7c7e3360841d82ab9c0d777b6799c4b37ad7d9746bf750f61
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 21, 2026.

Transparency log

Release files / corto_cache-0.1.1-cp314-cp314-musllinux_1_2_aarch64.whl

Download URL corto_cache-0.1.1-cp314-cp314-musllinux_1_2_aarch64.whl
Size 476.2 kB
Tags CPython 3.14 Linux musl 1.2+ ARM64
SHA-256 checksum
How to use checksums
57f897837f7cf18ba7c2fee705c4f99bc382a9e84d8e824d4662b26062e2cb88
BLAKE2b-256 checksum
How to use checksums
94b4d1e08faf44a9e388a45fa2904505a7e82464ddb6963ab8f3cdfaddaf5428
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 21, 2026.

Transparency log

Release files / corto_cache-0.1.1-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl

Download URL corto_cache-0.1.1-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Size 507.8 kB
Tags CPython 3.14 Linux glibc 2.17+ x86-64 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
c72711b6e8b82ce25c7b8620d87ffba56d470103397b6dfe542c53b4d46ee5fc
BLAKE2b-256 checksum
How to use checksums
8ca98486da6cb0bb013edd4b388e9c0a0ab09832520d1d0552de0e77b0f3bc49
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 21, 2026.

Transparency log

Release files / corto_cache-0.1.1-cp314-cp314-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl

Download URL corto_cache-0.1.1-cp314-cp314-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl
Size 503.0 kB
Tags CPython 3.14 Linux glibc 2.17+ ARM64 Linux glibc 2.28+ ARM64
SHA-256 checksum
How to use checksums
80ed515fca062d05231e7b8cbdff9421672d3b0f06fd0d59b8a8048d197f6686
BLAKE2b-256 checksum
How to use checksums
63879bbde8385ec354454ef21a87943115d2479652f2f023e932599c09583941
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 21, 2026.

Transparency log

Release files / corto_cache-0.1.1-cp314-cp314-macosx_11_0_arm64.whl

Download URL corto_cache-0.1.1-cp314-cp314-macosx_11_0_arm64.whl
Size 78.5 kB
Tags CPython 3.14 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
af63c9740747431e08ced2e78cc0ca8540cd466d99bfb1281b721e1bc8a99104
BLAKE2b-256 checksum
How to use checksums
89890672fce595255cabd31bb66952429f72e2ffd47b8d4ad91c6deb07631aed
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 21, 2026.

Transparency log

Release files / corto_cache-0.1.1-cp314-cp314-macosx_10_15_x86_64.whl

Download URL corto_cache-0.1.1-cp314-cp314-macosx_10_15_x86_64.whl
Size 76.8 kB
Tags CPython 3.14 macOS 10.15+ x86-64
SHA-256 checksum
How to use checksums
1212f81f24122101080e14e514a553ade8e9f1354d752611eebd9830a629ac40
BLAKE2b-256 checksum
How to use checksums
67344a15059c4ba2a63179aaa4d51e297a96834f92bb2086552c6f4b1f45a219
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 21, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.1.1 This release

8 release files

0.1.0

6 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page