Koreader: Suggestion: keep the cache for a specific epub

Created on 13 Mar 2018  路  3Comments  路  Source: koreader/koreader

Now that opening a big epub from cache is really fast ( https://github.com/koreader/crengine/pull/100 ), would be nice to have a option to keep the cache made for a specific epub file; so koreader won麓t be able to delete this specific cache file.

This will prevent koreader from deleting the "marked" cache file in some recycling if the cache space is all used.

The option will be off at default

Don麓t know if this is possible, but I leave my suggestion here.

enhancement

Most helpful comment

crengine does not use these.
We give it path and a hardcoded size here:
https://github.com/koreader/koreader/blob/5e557e22198cfdfdf4503e31fa57229124ac4b43/frontend/document/credocument.lua#L58
We could at least make it use a manually added setting, to use its value in place of this 32, so people who have free space can push it to 512 and have less chance to have book caches deleted.

I'm still giving some thoughts about this issue.
The fact is that this cache cleanup is managed totally by crengine: it cleans the less recently used.
We have a few options: have crengine manage an internal flag in cache files (or the index) for permanent-never-to-consider-for-cleanup, via cre.cpp methods - but hard to manage/keep up from koreader, as caches file have filename-truncated+crc32 names, not easily revertable.
Or just have a flag in docsettings, and call initCache() with a different path and a huge size when such a "keep the cache" book is called (but re-calling initCache() is prone to memory leaks).

I personally have some patch to store cache in RAM (/dev/ko_cache/), and some tweaks in credocument.lua like:

        cre_cache_state = "ram"
        -- Cache on disk for big books in Reference/
        if self.file:match("/mnt/onboard/.LIBRARY/Reference") then
            cre_cache_state = "disk"
        end
        -- if cache state changed, re initCache() with the appropriate parameters

But that what mainly just to not wear the SDCard, and to have a bit of speedup in openings (which wasn't really as much as I expected...)
I'd like to make crengine at least not update/write to the cache on close when we did not change anything to style or renderings - it does that actually, so, closing a big document takes 10 seconds, which is bothering (I could then get rid of that patch).

All 3 comments

Note that among other things you are able to increase the max cache size in persistent.defaults.lua. Not quite the same but perhaps it could help?

https://github.com/koreader/koreader/blob/78fbc145e40ae5b57dc04f5a2281bdfe96bfd1b5/defaults.lua#L25-L32

The 1024*1024 meaning megabytes, so the *60 makes 60 MiB. I forget what device you have but if it has 512 MB of RAM you can probably safely double that. Also see #1672.

That's used here:
https://github.com/koreader/koreader/blob/773e24fc79c8cbf6dcf48e3678237861149aabef/frontend/cache.lua#L32-L37

PS Sometimes backend changes invalidate the cache.

crengine does not use these.
We give it path and a hardcoded size here:
https://github.com/koreader/koreader/blob/5e557e22198cfdfdf4503e31fa57229124ac4b43/frontend/document/credocument.lua#L58
We could at least make it use a manually added setting, to use its value in place of this 32, so people who have free space can push it to 512 and have less chance to have book caches deleted.

I'm still giving some thoughts about this issue.
The fact is that this cache cleanup is managed totally by crengine: it cleans the less recently used.
We have a few options: have crengine manage an internal flag in cache files (or the index) for permanent-never-to-consider-for-cleanup, via cre.cpp methods - but hard to manage/keep up from koreader, as caches file have filename-truncated+crc32 names, not easily revertable.
Or just have a flag in docsettings, and call initCache() with a different path and a huge size when such a "keep the cache" book is called (but re-calling initCache() is prone to memory leaks).

I personally have some patch to store cache in RAM (/dev/ko_cache/), and some tweaks in credocument.lua like:

        cre_cache_state = "ram"
        -- Cache on disk for big books in Reference/
        if self.file:match("/mnt/onboard/.LIBRARY/Reference") then
            cre_cache_state = "disk"
        end
        -- if cache state changed, re initCache() with the appropriate parameters

But that what mainly just to not wear the SDCard, and to have a bit of speedup in openings (which wasn't really as much as I expected...)
I'd like to make crengine at least not update/write to the cache on close when we did not change anything to style or renderings - it does that actually, so, closing a big document takes 10 seconds, which is bothering (I could then get rid of that patch).

I propose this simple solution https://github.com/koreader/crengine/pull/137 as a way to keep some cache files.
It's not integrated into Koreader UI, because it would be hard to do and complicate many things - for an option that would not interest many users, and would be hard to explain.
(and when we have a FileManager that can display all files that are non-book, one will be able to do this rename from koreader itself - but he would need to know this trick)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

user655362020 picture user655362020  路  3Comments

Hzj-jie picture Hzj-jie  路  4Comments

gbyl picture gbyl  路  3Comments

hpdung99 picture hpdung99  路  4Comments

gerroon picture gerroon  路  4Comments