Skip to content

Add caching for Kroki diagrams #1601

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
Open

Conversation

theletterf
Copy link
Contributor

This continues #1599

Overview

This PR implements a diagram caching system to improve performance and reliability for documentation builds. The system provides local SVG caching with fallback to Kroki URLs. Hopefully I steered Claude correctly on this one...

Features

  • Automatically downloads and caches diagram SVGs locally during build
  • Content-based hashing (SHA256) prevents duplicate downloads
  • Meaningful filenames: {markdown-file}-diagram-{type}-{hash}.svg
  • Asynchronous, non-blocking downloads using fire-and-forget pattern
  • Registry-based tracking of active diagrams during builds
  • Automatic cleanup of unused/stale cached files after build completion
  • Prevents cache directory bloat over time
  • Shared HttpClient singleton prevents socket exhaustion
  • Connection reuse across all diagram downloads
  • 30-second timeout configuration for reliable network handling
  • Atomic file writes prevent corruption during concurrent operations

Copy link

github-actions bot commented Jul 22, 2025

🔍 Preview links for changed docs

@theletterf
Copy link
Contributor Author

@Mpdreamz @reakaleek An experiment. For reasons I don't fully understand, the local cache isn't used by the preview in this PR, but it does work locally.

@theletterf
Copy link
Contributor Author

@Mpdreamz Thanks! Most changes applied I'd say. Still wonder why the preview doesn't use the cached SVGs though. I guess the proper docs build will?

Copy link
Member

@Mpdreamz Mpdreamz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a few more review comments

@Mpdreamz
Copy link
Member

Still wonder why the preview doesn't use the cached SVGs though. I guess the proper docs build will?

Will dig into it at some point this week!

@theletterf theletterf requested a review from Mpdreamz July 23, 2025 09:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants