summaryrefslogtreecommitdiff
path: root/xmake/modules/private/cache/build_cache.lua
diff options
context:
space:
mode:
authorruki <[email protected]>2022-05-21 22:55:22 +0800
committerruki <[email protected]>2022-05-21 22:55:22 +0800
commit593e92dc0691eaaf3e1217fcf47161dc856af05e (patch)
treed8dc2099c3d00b5f2ce718c96e4090e80cfda033 /xmake/modules/private/cache/build_cache.lua
parentbcde9c9f0f7b2f51e20ccf1a4fccb08dc0b2f9e4 (diff)
add existinfo
Diffstat (limited to 'xmake/modules/private/cache/build_cache.lua')
-rw-r--r--xmake/modules/private/cache/build_cache.lua27
1 files changed, 22 insertions, 5 deletions
diff --git a/xmake/modules/private/cache/build_cache.lua b/xmake/modules/private/cache/build_cache.lua
index 96d777c1b..b62165f29 100644
--- a/xmake/modules/private/cache/build_cache.lua
+++ b/xmake/modules/private/cache/build_cache.lua
@@ -25,6 +25,16 @@ import("core.project.config")
import("private.service.client_config")
import("private.service.remote_cache.client", {alias = "remote_cache_client"})
+-- get exist info
+function _get_existinfo()
+ local existinfo = _g.existinfo
+ if existinfo == nil then
+ existinfo = remote_cache_client.singleton():existinfo()
+ _g.existinfo = existinfo
+ end
+ return existinfo
+end
+
-- is enabled?
function is_enabled()
local build_cache = _g.build_cache
@@ -135,11 +145,18 @@ function put(cachekey, objectfile)
os.cp(objectfile, objectfile_cached)
_g.newfiles_count = (_g.newfiles_count or 0) + 1
if remote_cache_client.is_connected() then
- -- TODO we need optimize it, decrease query count
- local cacheinfo = remote_cache_client.singleton():cacheinfo(cachekey)
- if not cacheinfo or not cacheinfo.exists then
- _g.remote_newfiles_count = (_g.remote_newfiles_count or 0) + 1
- remote_cache_client.singleton():push(cachekey, objectfile)
+ -- this file does not exist in remote server? push it to server
+ --
+ -- we use the bloom filter to approximate whether it exists or not,
+ -- which may result in a few less files being uploaded, but that's fine.
+ local existinfo = _get_existinfo()
+ if not existinfo or not existinfo:get(cachekey) then
+ -- existinfo is just an initial snapshot, we need to go further and determine if the current file exists
+ local cacheinfo = remote_cache_client.singleton():cacheinfo(cachekey)
+ if not cacheinfo or not cacheinfo.exists then
+ _g.remote_newfiles_count = (_g.remote_newfiles_count or 0) + 1
+ remote_cache_client.singleton():push(cachekey, objectfile)
+ end
end
end
end