md2star.cache module
Per-user cache directory for md2star image/mermaid artifacts.
Module summary
Historically, downscaled images, downloaded remote images, and rendered
mermaid PNGs all landed next to the user’s source Markdown, cluttering
working directories with hidden dotfiles (.remote_*, *_max1600.*,
*_cell.*, .mermaid_*). This module centralises every artifact under
$XDG_CACHE_HOME/md2star/ (with platform fallbacks) so the user’s source
trees stay clean and the cache can be wiped with a single
md2star clear-cache.
Cache layout:
$XDG_CACHE_HOME/md2star/
├── remote/ # downloaded http(s):// images, keyed by URL MD5
├── resized/ # downscaled rasters, keyed by source-path + size MD5
├── cell/ # cell-fitted images, keyed by source-path MD5
└── mermaid/ # rendered mermaid PNGs + resolved config JSON
The hash-keyed filenames make collisions across users impossible — two different source files with the same basename do not stomp each other.
Usage
>>> from md2star.cache import cache_dir, clear_cache
>>> p = cache_dir("remote")
>>> print(p.name) # 'remote'
remote
>>> freed = clear_cache()
>>> print(freed >= 0) # True
True