r/Python • • 21d ago

Showcase Showcase Thread

Post all of your code/projects/showcases/AI slop here.

Recycles once a month.

28 Upvotes

154 comments sorted by

View all comments

1

u/alexis-jeandet 20d ago

SciQLop Cache: a diskcache-compatible persistent cache with a C++ core, built for big numpy arrays


What My Project Does

pysciqlop-cache is a persistent key-value cache for Python. You store any picklable object under a string key, and any thread or process on the machine can read it back, safely, even at the same time.

from pysciqlop_cache import Cache

cache = Cache("/tmp/my-cache")
cache["sensor/temperature"] = {"ts": 1710000000, "values": [21.3, 21.5]}
print(cache["sensor/temperature"])

Small values live in SQLite. Big ones go to files, which are memory-mapped on read. It has expiration, tags, an optional size limit with LRU eviction, transactions, and a memoize decorator.

We built it for SciQLop and speasy, tools for space physics data, where a cached value is often a 10 to 100 MB time series. That's where most of the work went:

  • An optional serializer stores numpy arrays next to the pickle instead of inside it. It compresses them when that pays off, and it copies them without holding the GIL, so threads loading data don't block each other.
  • The cache is safe with forked worker pools, crashes, and processes racing each other. cache.check(fix=True) repairs what it finds.
  • It runs on free-threaded Python (3.13t+) too.

Target Audience

Anyone who caches expensive results to disk and shares the cache between processes: scientific code, data pipelines, notebooks, worker pools. It's in production in speasy, and it's on PyPI with wheels for Linux, macOS and Windows (x86-64 and ARM).

Comparison

The obvious comparison is diskcache. The API is mostly the same on purpose, and one command migrates an existing diskcache directory:

python -m pysciqlop_cache.migrate /path/to/diskcache /path/to/new-cache

Benchmarks with both libraries at their default settings, on a RAM filesystem (Ryzen 7 5800X and Apple M2):

  • Writes are about 2x faster, and up to 6x in batched transactions.
  • Latency stays flat from 100 to 1M entries, and a size limit costs nothing.
  • numpy arrays (100 KB to 100 MB): writes ~5x faster at 100 MB, single-thread reads 3x to 14x faster below 1 MB, and multi-threaded reads keep scaling (9.6 GB/s at 16 threads vs 7.9 GB/s).

Where diskcache wins: values between 8 KB and 32 KB. We store those as files, and diskcache keeps them in SQLite, so our writes are about 1.8x slower in that range on Linux.

Methodology and all the charts: https://sciqlop-cache.readthedocs.io/en/latest/performance.html

Docs: https://sciqlop-cache.readthedocs.io

Feedback welcome, especially on the API and on workloads where it falls short.