From 12d161c1cee04520054acbc175d0d56c5f2f058a Mon Sep 17 00:00:00 2001 From: Barrett Ruth Date: Sun, 22 Feb 2026 15:48:13 -0500 Subject: [PATCH 1/2] fix(cache): invalidate stale cache on version mismatch Problem: after an install or update, the on-disk cache may contain data written by an older version of the plugin whose format no longer matches what the current code expects. Solution: embed a CACHE_VERSION in every saved cache file. On load, if the stored version is missing or differs from the current one, wipe the cache and rewrite it. Corrupt (non-decodable) cache files are handled the same way instead of only logging an error. --- lua/cp/cache.lua | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/lua/cp/cache.lua b/lua/cp/cache.lua index 544aaf4..f3d0a94 100644 --- a/lua/cp/cache.lua +++ b/lua/cp/cache.lua @@ -38,6 +38,8 @@ local M = {} +local CACHE_VERSION = 1 + local logger = require('cp.log') local cache_file = vim.fn.stdpath('data') .. '/cp-nvim.json' local cache_data = {} @@ -65,9 +67,15 @@ function M.load() local ok, decoded = pcall(vim.json.decode, table.concat(content, '\n')) if ok then - cache_data = decoded + if decoded._version ~= CACHE_VERSION then + cache_data = {} + M.save() + else + cache_data = decoded + end else - logger.log('Could not decode json in cache file', vim.log.levels.ERROR) + cache_data = {} + M.save() end loaded = true end @@ -78,6 +86,7 @@ function M.save() vim.schedule(function() vim.fn.mkdir(vim.fn.fnamemodify(cache_file, ':h'), 'p') + cache_data._version = CACHE_VERSION local encoded = vim.json.encode(cache_data) local lines = vim.split(encoded, '\n') vim.fn.writefile(lines, cache_file) From 79237aef8a1208efe9ee41e17d722d642d0abfd9 Mon Sep 17 00:00:00 2001 From: Barrett Ruth Date: Sun, 22 Feb 2026 15:54:04 -0500 Subject: [PATCH 2/2] fix(cache): remove unused logger import Problem: the logger import became unused after replacing the error log with a silent cache wipe. Solution: drop the require. --- lua/cp/cache.lua | 1 - 1 file changed, 1 deletion(-) diff --git a/lua/cp/cache.lua b/lua/cp/cache.lua index f3d0a94..efdcad7 100644 --- a/lua/cp/cache.lua +++ b/lua/cp/cache.lua @@ -40,7 +40,6 @@ local M = {} local CACHE_VERSION = 1 -local logger = require('cp.log') local cache_file = vim.fn.stdpath('data') .. '/cp-nvim.json' local cache_data = {} local loaded = false