Skip to content

fix(cache): prevent random FileNotFoundException when reading chapters#3154

Open
leodyversemilla07 wants to merge 2 commits intomihonapp:mainfrom
leodyversemilla07:fix/reader-cache-filenotfound
Open

fix(cache): prevent random FileNotFoundException when reading chapters#3154
leodyversemilla07 wants to merge 2 commits intomihonapp:mainfrom
leodyversemilla07:fix/reader-cache-filenotfound

Conversation

@leodyversemilla07
Copy link
Copy Markdown
Contributor

@leodyversemilla07 leodyversemilla07 commented Mar 26, 2026

Summary

This PR addresses the random FileNotFoundException reported in #2740 by making chapter cache validation more robust and increasing its capacity.

The Bug

The chapter cache validation was previously only checking the cache index (journal). If the index was stale or the physical file had been evicted/deleted (due to the small 100MB limit or OS intervention), the loader would erroneously skip the download and attempt to open a non-existent file.

The Fix

  • Increased cache size: Bumped from 100 MiB to 200 MiB to reduce aggressive evictions of cached images (adjusted from 500 MiB based on maintainer feedback).
  • Physical verification: Added a mandatory .exists() check in isImageInCache to ensure the file is actually present on disk before reporting it as cached.
  • Logging: Added a logcat warning when the index and disk are out of sync to aid future diagnostics.

Checklist

  • I have tested my code and done a self-review.
  • Tested reader behavior with and without cached images.
  • Verified that isImageInCache correctly triggers re-downloads when files are manually deleted from the cache directory.

Fixes #2740

@MajorTanya
Copy link
Copy Markdown
Member

500 MB cache is aggressive. I don't think the lower end devices Mihon is used on could handle that well.

@leodyversemilla07
Copy link
Copy Markdown
Contributor Author

leodyversemilla07 commented Mar 26, 2026

500 MB cache is aggressive. I don't think the lower end devices Mihon is used on could handle that well.

what do you think would be the sweet spot?

@leodyversemilla07
Copy link
Copy Markdown
Contributor Author

I've reduced the cache size to 200 MiB (doubling the original 100 MiB) to be less aggressive for lower-end devices while still providing more headroom for high-res images. The primary fix of adding physical file existence checks remains unchanged.

- Increase chapter cache size to 500 MiB to reduce aggressive evictions.
- Add physical file existence check in isImageInCache to detect stale index entries.
- Add warning log for index/disk desynchronization.

Fixes mihonapp#2740
@leodyversemilla07 leodyversemilla07 force-pushed the fix/reader-cache-filenotfound branch from 14cca97 to c58cf8f Compare March 27, 2026 00:38
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.

Random FileNotFoundException when reading chapters

2 participants