Skip to main content

README.md

1# funkycache
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.
6Example:
8```python
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
27```
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.
35## Installation
37Install using pip:
39```console
40$ pip install funkycache
41```
43## License
45This project is shared under the [MIT license](./LICENSE).