Skip to content

Commit 80a2b71

Browse files
committed
refactor: less code for cache
1 parent cfc3933 commit 80a2b71

File tree

1 file changed

+8
-22
lines changed

1 file changed

+8
-22
lines changed

lua/lazy/core/cache.lua

+8-22
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
-- Simple string cache with fast saving and loading from file
22
local M = {}
33

4-
local cache_path = vim.fn.stdpath("state") .. "/lazy/plugins.state"
5-
---@type string
6-
local cache_hash = nil
7-
local dirty = false
4+
M.dirty = false
85

6+
local cache_path = vim.fn.stdpath("state") .. "/lazy.state"
7+
---@type string
8+
local cache_hash = ""
99
---@type table<string,boolean>
1010
local used = {}
11-
1211
---@type table<string,string>
1312
local cache = {}
1413

@@ -23,24 +22,12 @@ end
2322
function M.set(key, value)
2423
cache[key] = value
2524
used[key] = true
26-
dirty = true
25+
M.dirty = true
2726
end
2827

2928
function M.del(key)
3029
cache[key] = nil
31-
dirty = true
32-
end
33-
34-
function M.dirty()
35-
dirty = true
36-
end
37-
38-
function M.use(pattern)
39-
for key, _ in pairs(cache) do
40-
if key:find(pattern) then
41-
used[key] = true
42-
end
43-
end
30+
M.dirty = true
4431
end
4532

4633
function M.hash(file)
@@ -56,7 +43,7 @@ function M.setup()
5643
callback = function()
5744
vim.api.nvim_create_autocmd("VimLeavePre", {
5845
callback = function()
59-
if dirty then
46+
if M.dirty then
6047
local hash = M.hash(cache_path)
6148
-- abort when the file was changed in the meantime
6249
if hash == nil or cache_hash == hash then
@@ -70,10 +57,9 @@ function M.setup()
7057
end
7158

7259
function M.save()
73-
require("lazy.core.state").save()
60+
require("lazy.core.plugin").save()
7461
require("lazy.core.module").save()
7562

76-
vim.fn.mkdir(vim.fn.fnamemodify(cache_path, ":p:h"), "p")
7763
local f = assert(io.open(cache_path, "wb"))
7864
for key, value in pairs(cache) do
7965
if used[key] then

0 commit comments

Comments
 (0)