3funkycache is a disk-backed cache for Python functions that tracks file dependencies.
4I use it in my static site generator to cache the output of expensive functions.
9from funkycache import FunkyCache
11cache = FunkyCache(storage="sqlite")
14@cache.register(files=["content/index.md", "templates/base.html"])
15def render_index() -> str:
16 page = Path("content/index.md").read_text()
17 template = Path("templates/base.html").read_text()
18 return template.replace("{{ content }}", page)
21print(render_index()) # runs the function
22print(render_index()) # cache hit, even in a new process
24cache.notify_path_change("content/index.md")
26print(render_index()) # runs the function again
29When you register a function with funkycache, you can declare path or static values the function depends on.
30If those dependent values change, the function's cache is invalidated, and the next call will rerun the function fresh.
32**Note:** funkycache does not watch the filesystem.
33It is your responsibility to notify it of changes to dependent files, or they will be noticed when the Python process restarts.
40$ pip install funkycache
45This project is shared under the [
MIT license](
./LICENSE).