Skip to content

fix: CacheableResponse should only download file when needed#2035

Merged
thomas-zahner merged 2 commits intolycheeverse:masterfrom
rina-forks:lazy-cacheable-response
Feb 11, 2026
Merged

fix: CacheableResponse should only download file when needed#2035
thomas-zahner merged 2 commits intolycheeverse:masterfrom
rina-forks:lazy-cacheable-response

Conversation

@katrinafyi
Copy link
Member

Fixes #2034

This changes the CacheableResponse's text field to be an Option. By default, responses will be cached without the body text so they can be checked quickly even if the file is large. Cached responses can be "upgraded" to include the body if fragments need to be checked inside that URL. Once upgraded, the response with body will be cached for future fragment checks.

This is not a very intelligent fix to the issue, I don't love passing needs_body: bool everywhere. But it does work and it's not very invasive.

Note that this caching of body text is slightly redundant, because FragmentChecker already caches its own set of anchors within each URL. But it could be useful if the text is needed for other things in future (recursion???).

Fixes https://www.github.com/lycheeverse/lychee/issues/2034

This changes the CacheableResponse's text field to be an Option.
By default, responses will be cached without the body text.
Cached responses can be "upgraded" to include the body if fragments need
to be checked inside that URL. Once upgraded, the response with body
will be cached for future fragment checks.

This is not a very intelligent fix to the issue, I don't love passing
`needs_body: bool` everywhere. But it does work and it's not very
invasive.

Note that this caching of body text is slightly redundant, because
FragmentChecker already caches its own set of anchors within each URL.
But it could be useful if the text is needed for other things in future
(recursion???).
@thomas-zahner
Copy link
Member

@katrinafyi Thank you for the PR! I see no issues with it apart from the test that could be made more precise.

This is not a very intelligent fix to the issue, I don't love passing needs_body: bool everywhere. But it does work and it's not very invasive.

I think this approach is totally fine.

@thomas-zahner thomas-zahner merged commit 147c7fc into lycheeverse:master Feb 11, 2026
7 checks passed
@mre mre mentioned this pull request Feb 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CacheableResponse forces download of entire HTTP response

3 participants