Skip to content

Commit c915ab5

Browse files
committed
fix: clearing api cache
1 parent 33ec630 commit c915ab5

File tree

2 files changed

+25
-18
lines changed

2 files changed

+25
-18
lines changed

lua/crates/core.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ local function update(buf, reload)
5858
buf = buf or util.current_buf()
5959

6060
if reload then
61-
state.api_cache = {}
61+
state:clear_cache()
6262
api.cancel_jobs()
6363
end
6464

lua/crates/state.lua

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,3 @@
1-
---@class State
2-
---@field cfg Config
3-
---@field api_cache table<string,ApiCrate>
4-
---@field buf_cache table<integer,BufCache>
5-
---@field search_cache SearchCache
6-
---@field visible boolean
7-
local State = {
8-
buf_cache = {},
9-
search_cache = {
10-
results = {},
11-
searches = {},
12-
},
13-
visible = true,
14-
}
15-
161
---@param name string
172
---@return string
183
local function normalize_crate_name(name)
@@ -41,8 +26,6 @@ function ApiCache:__newindex(key, value)
4126
return rawset(self, id, value)
4227
end
4328

44-
State.api_cache = ApiCache.new()
45-
4629
---@class BufCache
4730
---@field crates table<string,TomlCrate>
4831
---@field info table<string,CrateInfo>
@@ -53,4 +36,28 @@ State.api_cache = ApiCache.new()
5336
---@field searches table<string, string[]>
5437
---@field results table<string, ApiCrateSummary>
5538

39+
---@class State
40+
---@field cfg Config
41+
---@field buf_cache table<integer,BufCache>
42+
---@field api_cache table<string,ApiCrate>
43+
---@field search_cache SearchCache
44+
---@field visible boolean
45+
local State = {
46+
buf_cache = {},
47+
api_cache = ApiCache.new(),
48+
search_cache = {
49+
results = {},
50+
searches = {},
51+
},
52+
visible = true,
53+
}
54+
55+
function State:clear_cache()
56+
self.api_cache = ApiCache.new()
57+
self.search_cache = {
58+
results = {},
59+
searches = {},
60+
}
61+
end
62+
5663
return State

0 commit comments

Comments
 (0)