@@ -2,6 +2,7 @@ local EventEmitter = require "mason-core.EventEmitter"
22local InstallLocation = require " mason-core.installer.InstallLocation"
33local log = require " mason-core.log"
44local path = require " mason-core.path"
5+ local settings = require " mason.settings"
56local uv = vim .loop
67local LazySourceCollection = require " mason-registry.sources"
78
@@ -165,18 +166,20 @@ function Registry.update(callback)
165166 a .run (update , callback or noop , Registry .sources )
166167end
167168
168- local REGISTRY_STORE_TTL = 86400 -- 24 hrs
169-
170169--- @param sources LazySourceCollection
171170--- @param callback ? RegistryUpdateCallback
172171local function refresh (sources , callback )
172+ if not settings .current .registry_cache .refresh then
173+ log .debug " Not performing a registry refresh as it's disabled in settings."
174+ return true , {}
175+ end
173176 local a = require " mason-core.async"
174177
175178 local state = sources :get_install_state ()
176179 if state and sources :is_all_installed () then
177180 local registry_age = os.time () - state .timestamp
178181
179- if registry_age <= REGISTRY_STORE_TTL and state .checksum == sources :checksum () then
182+ if registry_age <= settings . current . registry_cache . duration and state .checksum == sources :checksum () then
180183 log .fmt_debug (
181184 " Registry refresh is not necessary yet. Registry age=%d, checksum=%s" ,
182185 registry_age ,
@@ -185,14 +188,14 @@ local function refresh(sources, callback)
185188 if callback then
186189 callback (true , {})
187190 end
188- return
191+ return true , {}
189192 end
190193 end
191194
192195 if not callback then
193196 -- We don't want to error in the synchronous version because of how this function is recommended to be used in
194197 -- 3rd party code. If accessing the update result is required, users are recommended to pass a callback.
195- pcall (a .run_blocking , update , sources )
198+ return pcall (a .run_blocking , update , sources )
196199 else
197200 a .run (update , callback , sources )
198201 end
@@ -201,13 +204,13 @@ end
201204--- @param callback ? RegistryUpdateCallback
202205function Registry .refresh (callback )
203206 log .debug " Refreshing the registry."
204- refresh (Registry .sources , callback )
207+ return refresh (Registry .sources , callback )
205208end
206209
207210--- @param callback ? RegistryUpdateCallback
208211function Registry .refresh_system (callback )
209212 log .debug " Refreshing the system registry."
210- refresh (Registry .system_sources , callback )
213+ return refresh (Registry .system_sources , callback )
211214end
212215
213216return Registry
0 commit comments