feat(cache): make ttl configurable

This commit is contained in:
Folke Lemaitre 2022-12-25 16:26:17 +01:00
parent 9837d5be7e
commit 4aa362e8dc
No known key found for this signature in database
GPG Key ID: 41F8B1FBACAE2040
2 changed files with 3 additions and 2 deletions

View File

@ -384,6 +384,7 @@ return {
-- * VimEnter: not useful to cache anything else beyond startup
-- * BufReadPre: this will be triggered early when opening a file from the command line directly
disable_events = { "VimEnter", "BufReadPre" },
ttl = 3600 * 24 * 5, -- keep unused modules for up to 5 days
},
reset_packpath = true, -- reset the package path to improve startup time
rtp = {

View File

@ -16,6 +16,7 @@ M.config = {
-- * VimEnter: not useful to cache anything else beyond startup
-- * BufReadPre: this will be triggered early when opening a file from the command line directly
disable_events = { "VimEnter", "BufReadPre" },
ttl = 3600 * 24 * 5, -- keep unused modules for up to 5 days
}
M.debug = false
@ -27,7 +28,6 @@ local cache_hash
---@type table<string,CacheEntry?>
M.cache = {}
M.enabled = true
M.ttl = 3600 * 24 * 5 -- keep unused modules for up to 5 days
---@type string[]
M.rtp = nil
-- selene:allow(global_usage)
@ -238,7 +238,7 @@ function M.save_cache()
uv.fs_write(f, M.VERSION)
uv.fs_write(f, "\0")
for modname, entry in pairs(M.cache) do
if entry.used > os.time() - M.ttl then
if entry.used > os.time() - M.config.ttl then
entry.modname = modname
local header = {
entry.hash.size,