hn.today

Funkycache: A Python library to cache functions in SQLite

alexwlchan.net4 points0 comments
Screenshot of Funkycache: A Python library to cache functions in SQLite

Funkycache is a Python library for memoizing function calls in SQLite, developed to make a static-site build faster and less error-prone. Unlike a basic cache that only stores values, it handles the logic of identifying calls, saving results, and invalidating outdated entries. A decorator registers a function; its full argument set is normalized so positional arguments, keyword arguments, and defaults produce the same key. Inputs are JSON-encoded and hashed with XXH64 to keep SQLite keys compact. A benchmark found XXH64 faster than storing large encoded keys directly or hashing them with MD5. Cached outputs are serialized as JSON and restored using Pydantic, which requires functions to have return-type annotations. For lazy generators, the library stores a materialized list and returns an iterator; a memory limit prevents caching excessively large or unbounded output.

Cache entries can also depend on files, folders, or static values such as a library version, so changes trigger recomputation. The function’s own source changes invalidate its cache as well. The design targets deterministic functions without side effects, and accepts some lossy input transformations because cache keys need not preserve original values. The motivation is to make caching logic testable once rather than repeatedly implementing it in individual build steps. The project also grew from an interest in reactive systems: a build could be modeled as a dependency graph, rebuilding only outputs affected by changed inputs. Funkycache supplies reusable caching machinery, while a complete reactive build framework remains an aspiration.

Read on alexwlchan.net0 comments on Hacker News

Summary generated by AI from the linked article. hn.today is not affiliated with Hacker News or Y Combinator.

More in Programming

The daily digest

Today's best Hacker News stories, summarized and screenshotted, one email a day.