summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorgly <[email protected]>2022-12-27 15:01:24 +0100
committergly <[email protected]>2022-12-27 15:01:24 +0100
commitd7f529554bb6ef5c77ed36b7b6afb89ccfac0f41 (patch)
tree9a26f113a8ce8ff2fcd2f62ffb4b67c3094eff46
parent71ff3a251e726fc4d16a7f5f03dc5c3b4eeb3654 (diff)
Use globalcache instead of custom cache file
-rw-r--r--xmake/modules/private/xrepo/quick_search/cache.lua31
1 files changed, 17 insertions, 14 deletions
diff --git a/xmake/modules/private/xrepo/quick_search/cache.lua b/xmake/modules/private/xrepo/quick_search/cache.lua
index 3612160d7..613e492b1 100644
--- a/xmake/modules/private/xrepo/quick_search/cache.lua
+++ b/xmake/modules/private/xrepo/quick_search/cache.lua
@@ -19,11 +19,11 @@
--
import("core.base.json")
-import("core.base.global")
+import("core.cache.globalcache")
import("core.package.package", {alias = "core_package"})
import("private.action.require.impl.repository")
-local CACHE_PATH = path.join(global.cachedir(), "repositories_data.json")
+local cache = globalcache.cache("quick_search")
-- search package directories from repositories
function _list_package_dirs()
@@ -46,32 +46,35 @@ function _list_package_dirs()
return packageinfos
end
+-- check cache content exists
+function _init()
+ if table.empty(cache:data()) then
+ update()
+ end
+end
+
-- update the cache file
function update()
- local result = {}
for _, packageinfo in ipairs(_list_package_dirs()) do
local package = core_package.load_from_repository(packageinfo.name, packageinfo.repo, packageinfo.packagedir)
- table.insert(result,{
- name = packageinfo.name,
+ cache:set(packageinfo.name, {
description = package:description(),
versions = package:versions(),
})
end
- io.writefile(CACHE_PATH, json.encode(result))
- return result
+ cache:save()
end
-- remove the cache file
function clear()
- if os.exists(CACHE_PATH) then
- os.rm(CACHE_PATH)
- end
+ cache:clear()
+ cache:save()
end
-- get the cache data
function get()
- if not os.exists(CACHE_PATH) then
- return update()
- end
- return json.decode(io.readfile(CACHE_PATH))
+ _init()
+ return cache:data()
+end
+
end \ No newline at end of file