mirror of
https://github.com/koreader/koreader.git
synced 2025-08-10 00:52:38 +00:00
Fontlist: Move cache file in a subdirectory, so as not to mess with
Cache's state tracking Re #7510 Legacy cache has to be deleted in Cache, *before* the first getDiskCache call. Reword the "Clear caches" Dev menu entry & callback: We now have an actual "Restart" action (on most, if not all, platforms). And we clear the whole cache folder, which may host other things (e.g., fontlist)
This commit is contained in:
@@ -378,10 +378,10 @@ To:
|
||||
text = _("Developer options"),
|
||||
sub_item_table = {
|
||||
{
|
||||
text = _("Clear readers' caches"),
|
||||
text = _("Clear caches"),
|
||||
callback = function()
|
||||
UIManager:show(ConfirmBox:new{
|
||||
text = _("Clear cache/ and cr3cache/ ?"),
|
||||
text = _("Clear the cache folder?"),
|
||||
ok_callback = function()
|
||||
local DataStorage = require("datastorage")
|
||||
local cachedir = DataStorage:getDataDir() .. "/cache"
|
||||
@@ -389,13 +389,12 @@ To:
|
||||
FFIUtil.purgeDir(cachedir)
|
||||
end
|
||||
lfs.mkdir(cachedir)
|
||||
-- Also remove from Cache objet references to
|
||||
-- the cache files we just deleted
|
||||
-- Also remove from the Cache objet references to the cache files we've just deleted
|
||||
local Cache = require("cache")
|
||||
Cache.cached = {}
|
||||
local InfoMessage = require("ui/widget/infomessage")
|
||||
UIManager:show(InfoMessage:new{
|
||||
text = _("Caches cleared. Please exit and restart KOReader."),
|
||||
text = _("Caches cleared. Please restart KOReader."),
|
||||
})
|
||||
end,
|
||||
})
|
||||
|
||||
@@ -39,6 +39,9 @@ end
|
||||
|
||||
local cache_path = DataStorage:getDataDir() .. "/cache/"
|
||||
|
||||
-- NOTE: Before 2021.04, fontlist used to squat our folder, needlessly polluting our state tracking.
|
||||
os.remove(cache_path .. "/fontinfo.dat")
|
||||
|
||||
--[[
|
||||
-- return a snapshot of disk cached items for subsequent check
|
||||
--]]
|
||||
|
||||
@@ -9,6 +9,7 @@ local dbg = require("dbg")
|
||||
|
||||
local FontList = {
|
||||
fontdir = "./fonts",
|
||||
cachedir = DataStorage:getDataDir() .. "/cache/fontlist", -- in a subdirectory, so as not to mess w/ the Cache module.
|
||||
fontlist = {},
|
||||
fontinfo = {},
|
||||
fontnames = {},
|
||||
@@ -169,12 +170,15 @@ function FontList:getFontList()
|
||||
if #self.fontlist > 0 then return self.fontlist end
|
||||
|
||||
local cache = Persist:new{
|
||||
path = DataStorage:getDataDir() .. "/cache/fontinfo.dat"
|
||||
path = self.cachedir .. "/fontinfo.dat"
|
||||
}
|
||||
|
||||
local t, err = cache:load()
|
||||
if not t then
|
||||
logger.info(cache.path, err, "initializing it")
|
||||
|
||||
-- Create new subdirectory
|
||||
lfs.mkdir(self.cachedir)
|
||||
end
|
||||
self.fontinfo = t or {}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user