From aca076c4191ab6a60e0771d0791f69ddc748aaf4 Mon Sep 17 00:00:00 2001 From: Hironori Kitagawa Date: Thu, 25 Jul 2019 07:39:28 +0900 Subject: [PATCH] stopped to use cache file for fonts --- src/ltj-base.lua | 19 +++++++++++++++---- src/ltj-jfont.lua | 29 ++++------------------------- 2 files changed, 19 insertions(+), 29 deletions(-) diff --git a/src/ltj-base.lua b/src/ltj-base.lua index 1ed8ab8..4182a60 100644 --- a/src/ltj-base.lua +++ b/src/ltj-base.lua @@ -257,7 +257,7 @@ do if lfs.isdir(testpath) then savepath = testpath; break end end - save_cache_luc = function (filename, t, serialized) + local function save_cache_luc(filename, t, serialized) local fullpath = savepath .. '/' .. filename .. luc_suffix local s = serialized or serialize(t, 'return', false) if s then @@ -271,7 +271,7 @@ do end end - save_cache = function (filename, t) + local function save_cache(filename, t) local fullpath = savepath .. '/' .. filename .. '.lua' local s = serialize(t, 'return', false) if s then @@ -285,7 +285,7 @@ do end end - local function load_cache_a (filename, outdate) + local function load_cache_a(filename, outdate) local result for _,v in pairs(path) do local fn = join(v, cache_dir, filename) @@ -302,7 +302,7 @@ do end end - load_cache = function (filename, outdate) + local function load_cache(filename, outdate) local r = load_cache_a(filename .. luc_suffix, outdate) if r then return r @@ -313,6 +313,17 @@ do end end + local function remove_file_if_exist(name) + if os.rename(name,name) then os.remove(name) end + end + local function remove_cache (filename) + local fullpath_wo_ext = savepath .. '/' .. filename .. '.lu' + remove_file_if_exist(fullpath_wo_ext .. 'a') + remove_file_if_exist(fullpath_wo_ext .. 'b') + remove_file_if_exist(fullpath_wo_ext .. 'c') + end + + ltjb.remove_cache = remove_cache ltjb.load_cache = load_cache ltjb.save_cache_luc = save_cache_luc ltjb.save_cache = save_cache diff --git a/src/ltj-jfont.lua b/src/ltj-jfont.lua index 09a5677..82e2808 100644 --- a/src/ltj-jfont.lua +++ b/src/ltj-jfont.lua @@ -827,35 +827,14 @@ end -- do - local cache_ver = 19 - local function prepare_extra_data_base(id) if (not id) or (not id.filename) then return end local bname = id.psname or file.nameonly(id.filename) if not font_extra_basename[bname] then - -- if the cache is present, read it - if not lfs then lfs=require"lfs" end - local newtime = lfs.attributes(id.filename,"modification") - local v = "extra_" .. string.lower(bname) - local dat = ltjb.load_cache( - v, - function (t) return (t.version~=cache_ver) or (t.modtime~=newtime) end - ) - -- if the cache is not found or outdated, save the cache - if dat then - font_extra_basename[bname] = dat[1] or {} - else - local dat = nil - dat = prepare_fl_data(dat, id) - dat = list_rotate_glyphs(dat, id) - font_extra_basename[bname] = dat or {} - ltjb.save_cache( v, - { - modtime = newtime, - version = cache_ver, - dat, - }) - end + ltjb.remove_cache("extra_" .. string.lower(bname)) -- remove cache + local dat = prepare_fl_data(dat, id) + dat = list_rotate_glyphs(dat, id) + font_extra_basename[bname] = dat or {} return bname end end -- 2.11.0