@@ -140,6 +140,66 @@ impl api::Host for ComponentCtx {
140140 Ok ( handle. into ( ) )
141141 }
142142
143+ async fn replace_insert (
144+ & mut self ,
145+ _handle : Resource < api:: ReplaceEntry > ,
146+ _options : api:: WriteOptions ,
147+ ) -> Result < Resource < api:: Body > , types:: Error > {
148+ Err ( Error :: Unsupported {
149+ msg : "Cache API primitives not yet supported" ,
150+ }
151+ . into ( ) )
152+ }
153+
154+ async fn await_entry (
155+ & mut self ,
156+ handle : Resource < api:: PendingEntry > ,
157+ ) -> Result < Resource < api:: Entry > , types:: Error > {
158+ let handle = CacheBusyHandle :: from ( handle) . into ( ) ;
159+ // Swap out for a distinct handle, so we don't hit a repeated `close`+`close_busy`:
160+ let entry = self . session_mut ( ) . cache_entry_mut ( handle) . await ?;
161+ let mut other_entry = entry. stub ( ) ;
162+ std:: mem:: swap ( entry, & mut other_entry) ;
163+ let task = PeekableTask :: spawn ( Box :: pin ( async move { Ok ( other_entry) } ) ) . await ;
164+ let h: CacheHandle = self
165+ . session_mut ( )
166+ . insert_cache_op ( PendingCacheTask :: new ( task) )
167+ . into ( ) ;
168+ Ok ( h. into ( ) )
169+ }
170+
171+ fn close_pending_entry (
172+ & mut self ,
173+ handle : Resource < api:: PendingEntry > ,
174+ ) -> Result < ( ) , types:: Error > {
175+ let handle = CacheBusyHandle :: from ( handle) . into ( ) ;
176+ // Don't wait for the transaction to complete; drop the future to cancel.
177+ let _ = self . session_mut ( ) . take_cache_entry ( handle) ?;
178+ Ok ( ( ) )
179+ }
180+
181+ async fn close_entry ( & mut self , handle : Resource < api:: Entry > ) -> Result < ( ) , types:: Error > {
182+ let _ = self
183+ . session_mut ( )
184+ . take_cache_entry ( handle. into ( ) ) ?
185+ . task ( )
186+ . recv ( )
187+ . await ?;
188+ Ok ( ( ) )
189+ }
190+
191+ async fn close_replace_entry (
192+ & mut self ,
193+ _handle : Resource < api:: ReplaceEntry > ,
194+ ) -> Result < ( ) , types:: Error > {
195+ Err ( Error :: Unsupported {
196+ msg : "Cache API primitives not yet supported" ,
197+ }
198+ . into ( ) )
199+ }
200+ }
201+
202+ impl api:: HostReplaceEntry for ComponentCtx {
143203 async fn replace (
144204 & mut self ,
145205 key : Vec < u8 > ,
@@ -152,7 +212,7 @@ impl api::Host for ComponentCtx {
152212 . into ( ) )
153213 }
154214
155- async fn replace_get_age_ns (
215+ async fn get_age_ns (
156216 & mut self ,
157217 _handle : Resource < api:: ReplaceEntry > ,
158218 ) -> Result < Option < api:: DurationNs > , types:: Error > {
@@ -162,7 +222,7 @@ impl api::Host for ComponentCtx {
162222 . into ( ) )
163223 }
164224
165- async fn replace_get_body (
225+ async fn get_body (
166226 & mut self ,
167227 _handle : Resource < api:: ReplaceEntry > ,
168228 _options : api:: GetBodyOptions ,
@@ -173,7 +233,7 @@ impl api::Host for ComponentCtx {
173233 . into ( ) )
174234 }
175235
176- async fn replace_get_hits (
236+ async fn get_hits (
177237 & mut self ,
178238 _handle : Resource < api:: ReplaceEntry > ,
179239 ) -> Result < Option < u64 > , types:: Error > {
@@ -183,7 +243,7 @@ impl api::Host for ComponentCtx {
183243 . into ( ) )
184244 }
185245
186- async fn replace_get_length (
246+ async fn get_length (
187247 & mut self ,
188248 _handle : Resource < api:: ReplaceEntry > ,
189249 ) -> Result < Option < u64 > , types:: Error > {
@@ -193,7 +253,7 @@ impl api::Host for ComponentCtx {
193253 . into ( ) )
194254 }
195255
196- async fn replace_get_max_age_ns (
256+ async fn get_max_age_ns (
197257 & mut self ,
198258 _handle : Resource < api:: ReplaceEntry > ,
199259 ) -> Result < Option < api:: DurationNs > , types:: Error > {
@@ -203,7 +263,7 @@ impl api::Host for ComponentCtx {
203263 . into ( ) )
204264 }
205265
206- async fn replace_get_stale_while_revalidate_ns (
266+ async fn get_stale_while_revalidate_ns (
207267 & mut self ,
208268 _handle : Resource < api:: ReplaceEntry > ,
209269 ) -> Result < Option < api:: DurationNs > , types:: Error > {
@@ -213,7 +273,7 @@ impl api::Host for ComponentCtx {
213273 . into ( ) )
214274 }
215275
216- async fn replace_get_state (
276+ async fn get_state (
217277 & mut self ,
218278 _handle : Resource < api:: ReplaceEntry > ,
219279 ) -> Result < Option < api:: LookupState > , types:: Error > {
@@ -223,7 +283,7 @@ impl api::Host for ComponentCtx {
223283 . into ( ) )
224284 }
225285
226- async fn replace_get_user_metadata (
286+ async fn get_user_metadata (
227287 & mut self ,
228288 _handle : Resource < api:: ReplaceEntry > ,
229289 _max_len : u64 ,
@@ -234,51 +294,7 @@ impl api::Host for ComponentCtx {
234294 . into ( ) )
235295 }
236296
237- async fn replace_insert (
238- & mut self ,
239- _handle : Resource < api:: ReplaceEntry > ,
240- _options : api:: WriteOptions ,
241- ) -> Result < Resource < api:: Body > , types:: Error > {
242- Err ( Error :: Unsupported {
243- msg : "Cache API primitives not yet supported" ,
244- }
245- . into ( ) )
246- }
247-
248- async fn await_entry (
249- & mut self ,
250- handle : Resource < api:: PendingEntry > ,
251- ) -> Result < Resource < api:: Entry > , types:: Error > {
252- let handle = CacheBusyHandle :: from ( handle) . into ( ) ;
253- // Swap out for a distinct handle, so we don't hit a repeated `close`+`close_busy`:
254- let entry = self . session_mut ( ) . cache_entry_mut ( handle) . await ?;
255- let mut other_entry = entry. stub ( ) ;
256- std:: mem:: swap ( entry, & mut other_entry) ;
257- let task = PeekableTask :: spawn ( Box :: pin ( async move { Ok ( other_entry) } ) ) . await ;
258- let h: CacheHandle = self
259- . session_mut ( )
260- . insert_cache_op ( PendingCacheTask :: new ( task) )
261- . into ( ) ;
262- Ok ( h. into ( ) )
263- }
264-
265- fn close_pending_entry (
266- & mut self ,
267- handle : Resource < api:: PendingEntry > ,
268- ) -> Result < ( ) , types:: Error > {
269- let handle = CacheBusyHandle :: from ( handle) . into ( ) ;
270- // Don't wait for the transaction to complete; drop the future to cancel.
271- let _ = self . session_mut ( ) . take_cache_entry ( handle) ?;
272- Ok ( ( ) )
273- }
274-
275- async fn close_entry ( & mut self , handle : Resource < api:: Entry > ) -> Result < ( ) , types:: Error > {
276- let _ = self
277- . session_mut ( )
278- . take_cache_entry ( handle. into ( ) ) ?
279- . task ( )
280- . recv ( )
281- . await ?;
297+ fn drop ( & mut self , _entry : Resource < api:: ReplaceEntry > ) -> wasmtime:: Result < ( ) > {
282298 Ok ( ( ) )
283299 }
284300}
0 commit comments