From 192f10c1d09e665f04dd5669fcaccc5abccbb9db Mon Sep 17 00:00:00 2001 From: ruki Date: Tue, 22 Dec 2020 00:37:21 +0800 Subject: improve localcache and globalcache --- xmake/core/cache/globalcache.lua | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) (limited to 'xmake/core/cache/globalcache.lua') diff --git a/xmake/core/cache/globalcache.lua b/xmake/core/cache/globalcache.lua index 2736cf2a4..812cf25f1 100644 --- a/xmake/core/cache/globalcache.lua +++ b/xmake/core/cache/globalcache.lua @@ -25,6 +25,7 @@ local _instance = _instance or {} -- load modules local table = require("base/table") local io = require("base/io") +local os = require("base/os") local path = require("base/path") local global = require("base/global") @@ -130,7 +131,14 @@ function globalcache.cache(cachename) end -- get all caches -function globalcache.caches() +function globalcache.caches(opt) + opt = opt or {} + if opt.flush then + for _, cachefile in ipairs(os.files(path.join(global.cachedir(), "*"))) do + local cachename = path.filename(cachefile) + globalcache.cache(cachename) + end + end return globalcache._CACHES end @@ -166,14 +174,12 @@ end -- clear the given cache, it will clear all caches if cache name is nil function globalcache.clear(cachename) - local caches = globalcache.caches() - if caches then - for _, cache in pairs(caches) do - if cachename then - if cache:name() == cachename then - cache:clear() - end - else + if cachename then + globalcache.cache(cachename):clear() + else + local caches = globalcache.caches({flush = true}) + if caches then + for _, cache in pairs(caches) do cache:clear() end end -- cgit v1.3.1