Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions cache-sync.wit
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/// FastEdge cache interface (synchronous variant).
interface cache-sync {
use cache-types.{payload, error};

/// Get the value associated with `key`.
///
/// Returns:
/// - `ok(some(value))` if the key exists.
/// - `ok(none)` if the key does not exist.
/// - `err(error)` if the operation fails.
get: func(key: string) -> result<option<payload>, error>;

/// Set the value for `key` with an optional expiry.
///
/// If the key already exists, its current value is overwritten.
/// If the key does not exist, a new key-value pair is created.
///
/// `ttl-ms` is the time-to-live in milliseconds. Pass `none` for no expiry.
///
/// Returns `err(error)` if the operation fails.
set: func(key: string, value: payload, ttl-ms: option<u64>) -> result<_, error>;

/// Delete the key-value pair associated with `key`.
///
/// If the key does not exist, this operation is a no-op.
///
/// Returns `err(error)` if the operation fails.
delete: func(key: string) -> result<_, error>;

/// Check whether `key` exists in the cache.
///
/// Returns:
/// - `ok(true)` if the key exists.
/// - `ok(false)` if the key does not exist.
/// - `err(error)` if the operation fails.
exists: func(key: string) -> result<bool, error>;

/// Increment the integer value stored at `key` by `delta`.
///
/// If the key does not exist, it is initialised to `0` before incrementing.
/// The operation is atomic. `delta` may be negative to decrement.
///
/// Returns the new value after the increment, or `err(error)` if the
/// operation fails (for example, if the stored value is not an integer).
incr: func(key: string, delta: s64) -> result<s64, error>;

/// Set or update the expiry of `key` to `ttl-ms` milliseconds from now.
///
/// If the key does not exist, returns `ok(false)`.
/// If the expiry was updated successfully, returns `ok(true)`.
/// Returns `err(error)` if the operation fails.
expire: func(key: string, ttl-ms: u64) -> result<bool, error>;
}
15 changes: 15 additions & 0 deletions cache-types.wit
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/// Shared cache types for cache interfaces.
interface cache-types {
type payload = list<u8>;

/// The set of errors that may be returned by cache operations.
variant error {
/// The requesting component does not have access to the specified cache
/// (which may or may not exist).
access-denied,
/// An unexpected internal error occurred.
internal-error,
/// An implementation-specific error occurred (for example, I/O).
other(string)
}
}
1 change: 1 addition & 0 deletions world.wit
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ world reactor {
import secret;
import key-value;
import utils;
Comment thread
ruslanti marked this conversation as resolved.
import cache-sync;
Comment thread
ruslanti marked this conversation as resolved.

export http-handler;
}