funkycache
A SQLite-backed cache for Python functions that tracks file dependencies.
funkycache is a disk-backed cache for Python functions that tracks file dependencies. I use it in my static site generator to cache the output of expensive functions.
Example:
from funkycache import FunkyCache
cache = FunkyCache(storage="sqlite")
@cache.register(files=["content/index.md", "templates/base.html"])
def render_index() -> str:
page = Path("content/index.md").read_text()
template = Path("templates/base.html").read_text()
return template.replace("{{ content }}", page)
print(render_index()) # runs the function
print(render_index()) # cache hit, even in a new process
cache.notify_path_change("content/index.md")
print(render_index()) # runs the function againWhen you register a function with funkycache, you can declare path or static values the function depends on. If those dependent values change, the function’s cache is invalidated, and the next call will rerun the function fresh.
Note: funkycache does not watch the filesystem. It is your responsibility to notify it of changes to dependent files, or they will be noticed when the Python process restarts.
Installation
Install using pip:
$ pip install funkycacheLicense
This project is shared under the MIT license.