From 80a2b71a0906f3956e6adc40d6d80bae1dba8e54 Mon Sep 17 00:00:00 2001 From: Folke Lemaitre Date: Fri, 25 Nov 2022 22:49:21 +0100 Subject: [PATCH] refactor: less code for cache --- lua/lazy/core/cache.lua | 30 ++++++++---------------------- 1 file changed, 8 insertions(+), 22 deletions(-) diff --git a/lua/lazy/core/cache.lua b/lua/lazy/core/cache.lua index a5af080..7737b68 100644 --- a/lua/lazy/core/cache.lua +++ b/lua/lazy/core/cache.lua @@ -1,14 +1,13 @@ -- Simple string cache with fast saving and loading from file local M = {} -local cache_path = vim.fn.stdpath("state") .. "/lazy/plugins.state" ----@type string -local cache_hash = nil -local dirty = false +M.dirty = false +local cache_path = vim.fn.stdpath("state") .. "/lazy.state" +---@type string +local cache_hash = "" ---@type table local used = {} - ---@type table local cache = {} @@ -23,24 +22,12 @@ end function M.set(key, value) cache[key] = value used[key] = true - dirty = true + M.dirty = true end function M.del(key) cache[key] = nil - dirty = true -end - -function M.dirty() - dirty = true -end - -function M.use(pattern) - for key, _ in pairs(cache) do - if key:find(pattern) then - used[key] = true - end - end + M.dirty = true end function M.hash(file) @@ -56,7 +43,7 @@ function M.setup() callback = function() vim.api.nvim_create_autocmd("VimLeavePre", { callback = function() - if dirty then + if M.dirty then local hash = M.hash(cache_path) -- abort when the file was changed in the meantime if hash == nil or cache_hash == hash then @@ -70,10 +57,9 @@ function M.setup() end function M.save() - require("lazy.core.state").save() + require("lazy.core.plugin").save() require("lazy.core.module").save() - vim.fn.mkdir(vim.fn.fnamemodify(cache_path, ":p:h"), "p") local f = assert(io.open(cache_path, "wb")) for key, value in pairs(cache) do if used[key] then