@@ -140,6 +140,63 @@ 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 ( & mut self , _handle : Resource < api:: ReplaceEntry > ) -> Result < ( ) , types:: Error > {
192+ Err ( Error :: Unsupported {
193+ msg : "Cache API primitives not yet supported" ,
194+ }
195+ . into ( ) )
196+ }
197+ }
198+
199+ impl api:: HostReplaceEntry for ComponentCtx {
143200 async fn replace (
144201 & mut self ,
145202 key : Vec < u8 > ,
@@ -152,7 +209,7 @@ impl api::Host for ComponentCtx {
152209 . into ( ) )
153210 }
154211
155- async fn replace_get_age_ns (
212+ async fn get_age_ns (
156213 & mut self ,
157214 _handle : Resource < api:: ReplaceEntry > ,
158215 ) -> Result < Option < api:: DurationNs > , types:: Error > {
@@ -162,7 +219,7 @@ impl api::Host for ComponentCtx {
162219 . into ( ) )
163220 }
164221
165- async fn replace_get_body (
222+ async fn get_body (
166223 & mut self ,
167224 _handle : Resource < api:: ReplaceEntry > ,
168225 _options : api:: GetBodyOptions ,
@@ -173,7 +230,7 @@ impl api::Host for ComponentCtx {
173230 . into ( ) )
174231 }
175232
176- async fn replace_get_hits (
233+ async fn get_hits (
177234 & mut self ,
178235 _handle : Resource < api:: ReplaceEntry > ,
179236 ) -> Result < Option < u64 > , types:: Error > {
@@ -183,7 +240,7 @@ impl api::Host for ComponentCtx {
183240 . into ( ) )
184241 }
185242
186- async fn replace_get_length (
243+ async fn get_length (
187244 & mut self ,
188245 _handle : Resource < api:: ReplaceEntry > ,
189246 ) -> Result < Option < u64 > , types:: Error > {
@@ -193,7 +250,7 @@ impl api::Host for ComponentCtx {
193250 . into ( ) )
194251 }
195252
196- async fn replace_get_max_age_ns (
253+ async fn get_max_age_ns (
197254 & mut self ,
198255 _handle : Resource < api:: ReplaceEntry > ,
199256 ) -> Result < Option < api:: DurationNs > , types:: Error > {
@@ -203,7 +260,7 @@ impl api::Host for ComponentCtx {
203260 . into ( ) )
204261 }
205262
206- async fn replace_get_stale_while_revalidate_ns (
263+ async fn get_stale_while_revalidate_ns (
207264 & mut self ,
208265 _handle : Resource < api:: ReplaceEntry > ,
209266 ) -> Result < Option < api:: DurationNs > , types:: Error > {
@@ -213,7 +270,7 @@ impl api::Host for ComponentCtx {
213270 . into ( ) )
214271 }
215272
216- async fn replace_get_state (
273+ async fn get_state (
217274 & mut self ,
218275 _handle : Resource < api:: ReplaceEntry > ,
219276 ) -> Result < Option < api:: LookupState > , types:: Error > {
@@ -223,7 +280,7 @@ impl api::Host for ComponentCtx {
223280 . into ( ) )
224281 }
225282
226- async fn replace_get_user_metadata (
283+ async fn get_user_metadata (
227284 & mut self ,
228285 _handle : Resource < api:: ReplaceEntry > ,
229286 _max_len : u64 ,
@@ -234,51 +291,7 @@ impl api::Host for ComponentCtx {
234291 . into ( ) )
235292 }
236293
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 ?;
294+ fn drop ( & mut self , _entry : Resource < api:: ReplaceEntry > ) -> wasmtime:: Result < ( ) > {
282295 Ok ( ( ) )
283296 }
284297}
0 commit comments