fix: M._cache holds stale reference after cache.load() #266
Labels
No labels
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
barrettruth/cp.nvim#266
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Description
In
lua/cp/cache.lua,M._cache = cache_datais evaluated at module load time, capturing a reference to the initial empty{}. WhenM.load()is called and reassignscache_data = decoded, the module-levelM._cachefield still points to the original empty table, not the live data.Any external code using
require('cp.cache')._cachefor inspection/debugging will see an empty table regardless of what has been loaded.Steps to reproduce
require('cp.cache').load()require('cp.cache')._cache— it is{}require('cp.cache').get_data_pretty()— this returns actual data (uses module-localcache_datacorrectly)Proposed fix
Either remove
M._cacheentirely (it's undocumented and only useful for debugging, covered better byget_data_pretty()), or change it to a getter function: