diff options
| author | ruki <[email protected]> | 2020-12-22 00:37:21 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2020-12-22 00:37:21 +0800 |
| commit | 192f10c1d09e665f04dd5669fcaccc5abccbb9db (patch) | |
| tree | a5771f72e9552972c6d144d0ccc6bdf3b85e33d3 /xmake/core/cache/localcache.lua | |
| parent | 709765844261afbf8c188914c638ee7ff9380fd4 (diff) | |
improve localcache and globalcache
Diffstat (limited to 'xmake/core/cache/localcache.lua')
| -rw-r--r-- | xmake/core/cache/localcache.lua | 24 |
1 files changed, 15 insertions, 9 deletions
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 |
