· python
funkycache: a Python library to cache functions in SQLite
Six months ago, I wrote an SQLite-backed cache to speed up the build system for this site.
A static site generator is an ideal candidate for caching, because there are lots of steps that have deterministic behaviour and no side effects. On a site with hundreds of pages, even a few milliseconds per step adds up to a meaningful improvement. That first cache was fairly basic.
It supported getting and setting strings, with a namespace for different functions, and not much else: from mosaic.cache import SQLiteCache cache = SQLiteCache("example.db") cache.set(namespace="fibonacci", key="10", value="55") print(cache.get(namespace="fibonacci", key="10"))This showed the value of a cache, but it provided cache storage, not cache logic. If I wanted to cache a function, I had to write per-function logic for saving values to the cache and retrieving them later.



