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/localcache.lua | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) (limited to 'xmake/core/cache/localcache.lua') diff --git a/xmake/core/cache/localcache.lua b/xmake/core/cache/localcache.lua index f6016ef60..7ba00e7cc 100644 --- a/xmake/core/cache/localcache.lua +++ b/xmake/core/cache/localcache.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 config = require("project/config") @@ -130,7 +131,14 @@ function localcache.cache(cachename) end -- get all caches -function localcache.caches() +function localcache.caches(opt) + opt = opt or {} + if opt.flush then + for _, cachefile in ipairs(os.files(path.join(config.cachedir(), "*"))) do + local cachename = path.filename(cachefile) + localcache.cache(cachename) + end + end return localcache._CACHES end @@ -166,14 +174,12 @@ end -- clear the given cache, it will clear all caches if cache name is nil function localcache.clear(cachename) - local caches = localcache.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 + localcache.cache(cachename):clear() + else + local caches = localcache.caches({flush = true}) + if caches then + for _, cache in pairs(caches) do cache:clear() end end -- cgit v1.3.1