Expand description
Binary cache for parsed ledgers.
This module provides a caching layer that can dramatically speed up subsequent loads of unchanged beancount files by serializing the parsed directives to a binary format using rkyv.
§How it works
- When loading a file, compute a hash of all source files
- Check if a cache file exists with a matching hash
- If yes, deserialize and return immediately (typically <1ms)
- If no, parse normally, serialize to cache, and return
§Cache location
By default, cache files are stored alongside the main ledger as a hidden
dotfile: ledger.beancount → .ledger.beancount.cache. This matches Python
beancount’s .{filename}.picklecache convention.
Two environment variables control the location, both compatible with
Python beancount and honored at the loader level (so any consumer of
load_cache_entry / save_cache_entry gets the kill switch for free):
BEANCOUNT_DISABLE_LOAD_CACHE: when set (even to an empty value),load_cache_entryreturnsNoneandsave_cache_entryis a no-op.BEANCOUNT_LOAD_CACHE_FILENAME: a path pattern that may contain{filename}(replaced with the source basename). Relative paths resolve against the source directory; absolute paths are used as-is. If the target directory doesn’t exist,save_cache_entrycreates it.
Structs§
- Archived
Cache Entry - An archived
CacheEntry - Archived
Cached Options - An archived
CachedOptions - Archived
Cached Plugin - An archived
CachedPlugin - Cache
Entry - Complete cache entry containing all data needed to restore a
LoadResult. - Cache
Entry Resolver - The resolver for an archived
CacheEntry - Cached
Options - Cached options - a serializable subset of Options.
- Cached
Options Resolver - The resolver for an archived
CachedOptions - Cached
Plugin - Cached plugin information.
- Cached
Plugin Resolver - The resolver for an archived
CachedPlugin
Constants§
- CACHE_
FILENAME_ ENV - Environment variable that overrides the default cache filename pattern.
- DISABLE_
CACHE_ ENV - Environment variable that disables the binary cache entirely when set.
Functions§
- cache_
disabled_ by_ env - Returns true if
BEANCOUNT_DISABLE_LOAD_CACHEis set in the environment. - cache_
path - Returns the cache file path for a given source file.
- default_
cache_ path - Returns the default cache file path (no env-var lookup).
- invalidate_
cache - Invalidate the cache for a file.
- load_
cache_ entry - Try to load a cache entry from disk.
- save_
cache_ entry - Save a cache entry to disk.