Skip to content

Commit

Permalink
Add the missing adapter calls for new cache operations (#419)
Browse files Browse the repository at this point in the history
The adapter was missing implementations for some new cache hostcalls. This PR adds them, but as the viceroy implementation of the cache api is still a todo!(), does not add any testing.
  • Loading branch information
elliottt authored Aug 28, 2024
1 parent ceed333 commit c4d5f7c
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions crates/adapter/src/fastly/cache.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use super::{convert_result, BodyHandle, FastlyStatus, RequestHandle};
use crate::{alloc_result_opt, TrappingUnwrap};

pub type BusyHandle = u32;
pub type CacheHandle = u32;

pub type CacheObjectLength = u64;
Expand Down Expand Up @@ -253,6 +254,45 @@ mod cache {
}
}

#[export_name = "fastly_cache#transaction_lookup_async"]
pub fn transaction_lookup_async(
cache_key_ptr: *const u8,
cache_key_len: usize,
options_mask: CacheLookupOptionsMask,
options: *const CacheLookupOptions,
cache_handle_out: *mut BusyHandle,
) -> FastlyStatus {
let cache_key = unsafe { slice::from_raw_parts(cache_key_ptr, cache_key_len) };
let options_mask = cache::LookupOptionsMask::from(options_mask);
let options = unsafe { cache::LookupOptions::from(*options) };
match cache::transaction_lookup_async(cache_key, options_mask, options) {
Ok(res) => {
unsafe {
*cache_handle_out = res;
}
FastlyStatus::OK
}
Err(e) => e.into(),
}
}

#[export_name = "fastly_cache#cache_busy_handle_wait"]
pub fn cache_busy_handle_wait(
handle: BusyHandle,
cache_handle_out: *mut CacheHandle,
) -> FastlyStatus {
match cache::cache_busy_handle_wait(handle) {
Ok(res) => {
unsafe {
*cache_handle_out = res;
}

FastlyStatus::OK
}
Err(e) => e.into(),
}
}

#[export_name = "fastly_cache#transaction_insert"]
pub fn transaction_insert(
handle: CacheHandle,
Expand Down Expand Up @@ -319,6 +359,11 @@ mod cache {
convert_result(cache::transaction_cancel(handle))
}

#[export_name = "fastly_cache#close_busy"]
pub fn close_busy(handle: BusyHandle) -> FastlyStatus {
convert_result(cache::close_busy(handle))
}

#[export_name = "fastly_cache#close"]
pub fn close(handle: CacheHandle) -> FastlyStatus {
convert_result(cache::close(handle))
Expand Down
Binary file modified lib/data/viceroy-component-adapter.wasm
Binary file not shown.

0 comments on commit c4d5f7c

Please sign in to comment.