@@ -33,14 +33,14 @@ function Cache:new()
33
33
}, self )
34
34
end
35
35
36
- function Cache :is_open (id )
36
+ function Cache :exists (id )
37
37
return self .cache [id ] ~= nil
38
38
end
39
39
40
40
--- @param id string
41
41
--- @param opts grapple.cache.options
42
42
function Cache :open (id , opts )
43
- if self . cache [ id ] then
43
+ if self : exists ( id ) then
44
44
self :close (id )
45
45
end
46
46
60
60
61
61
--- @param id string
62
62
function Cache :close (id )
63
- local cache_value = self .cache [id ]
64
- if not cache_value then
63
+ if not self :exists (id ) then
65
64
return
66
65
end
67
66
67
+ local cache_value = self .cache [id ]
68
68
if cache_value .watching then
69
69
self :unwatch (id )
70
70
end
74
74
75
75
--- @param id string
76
76
function Cache :watch (id )
77
- local cache_value = self .cache [id ]
78
- if not cache_value then
77
+ if not self :exists (id ) then
79
78
return
80
79
end
81
80
81
+ local cache_value = self .cache [id ]
82
82
if cache_value .watching then
83
83
self :unwatch (id )
84
84
end
@@ -93,7 +93,7 @@ function Cache:watch(id)
93
93
if cache_value .debounce then
94
94
cache_value .debouncing = true
95
95
96
- local timer = vim .loop .new_timer ()
96
+ local timer = assert ( vim .loop .new_timer () )
97
97
timer :start (cache_value .debounce , 0 , function ()
98
98
cache_value .debouncing = false
99
99
end )
@@ -118,13 +118,13 @@ end
118
118
119
119
--- @param id string
120
120
function Cache :unwatch (id )
121
- local cache_value = self .cache [id ]
122
- if not cache_value then
121
+ if not self :exists (id ) then
123
122
return
124
123
end
125
124
126
125
self :invalidate (id )
127
126
127
+ local cache_value = self .cache [id ]
128
128
if cache_value .au_id then
129
129
vim .api .nvim_del_autocmd (cache_value .au_id )
130
130
end
@@ -139,10 +139,11 @@ end
139
139
--- @param id string
140
140
--- @return any cached_value
141
141
function Cache :get (id )
142
- local cache_value = self .cache [id ]
143
- if not cache_value then
142
+ if not self :exists (id ) then
144
143
return
145
144
end
145
+
146
+ local cache_value = self .cache [id ]
146
147
if not cache_value .watching then
147
148
self :watch (id )
148
149
end
@@ -153,10 +154,11 @@ end
153
154
--- @param id string
154
155
--- @param value any
155
156
function Cache :store (id , value )
156
- local cache_value = self .cache [id ]
157
- if not cache_value then
157
+ if not self :exists (id ) then
158
158
return
159
159
end
160
+
161
+ local cache_value = self .cache [id ]
160
162
if not cache_value .watching then
161
163
self :watch (id )
162
164
end
@@ -166,12 +168,11 @@ end
166
168
167
169
--- @param id string
168
170
function Cache :invalidate (id )
169
- local cache_value = self .cache [id ]
170
- if not cache_value then
171
+ if not self :exists (id ) then
171
172
return
172
173
end
173
174
174
- cache_value .value = nil
175
+ self . cache [ id ] .value = nil
175
176
end
176
177
177
178
return Cache
0 commit comments