[fix] Cache: don't overwrite same CacheItem (#3847)

If the most recently used global cache item refers to the same
page, it would be overwritten. This will happen when closing a
paged (PDF/DjVu) document on the same page you opened it, as well
as when opening and closing EPUBs with crengine because it uses
its own cache.

Fixes #3846.
pull/3850/head
Frans de Jonge 6 years ago committed by GitHub
parent d7a7a78731
commit 0e61eb7a7b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -162,10 +162,16 @@ function Cache:serialize()
local cache_size = 0
for _, key in ipairs(self.cache_order) do
local cache_item = self.cache[key]
-- only dump cache item that requests serialization explicitly
if cache_item.persistent and cache_item.dump then
local cache_full_path = cache_path..md5.sum(key)
local cache_file_exists = lfs.attributes(cache_full_path)
if cache_file_exists then break end
logger.dbg("dump cache item", key)
cache_size = cache_item:dump(cache_path..md5.sum(key)) or 0
cache_size = cache_item:dump(cache_full_path) or 0
if cache_size > 0 then break end
end
end

Loading…
Cancel
Save