Skip to content

Commit

Permalink
feat(cache): make ttl configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
folke committed Dec 25, 2022
1 parent 9837d5b commit 4aa362e
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
4 changes: 2 additions & 2 deletions lua/lazy/core/cache.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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)
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 4aa362e

Please sign in to comment.