From 2096eea4b094799c1df156f0336ae64dbfaccd3b Mon Sep 17 00:00:00 2001 From: Ruslan Pislari Date: Mon, 27 Apr 2026 13:42:29 +0300 Subject: [PATCH 1/6] feat: added cache and cache-sync interfaces --- cache.wit | 126 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ world.wit | 2 + 2 files changed, 128 insertions(+) create mode 100644 cache.wit diff --git a/cache.wit b/cache.wit new file mode 100644 index 0000000..ad8df06 --- /dev/null +++ b/cache.wit @@ -0,0 +1,126 @@ +/// Shared cache types for sync and async interfaces. +interface cache-types { + type payload = list; + + /// 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) + } +} + +/// FastEdge cache interface (async variant). +/// +/// This keeps the original `cache` name for backward compatibility with +/// existing async consumers. +interface cache { + 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: async func(key: string) -> result, 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: async func(key: string, value: payload, ttl-ms: option) -> 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: async 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: async func(key: string) -> result; + + /// 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: async func(key: string, delta: s64) -> result; + + /// 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: async func(key: string, ttl-ms: u64) -> result; +} + +/// 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, 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) -> 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; + + /// 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; + + /// 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; +} diff --git a/world.wit b/world.wit index 33587c9..fb4969a 100644 --- a/world.wit +++ b/world.wit @@ -7,6 +7,8 @@ world reactor { import secret; import key-value; import utils; + import cache; + import cache-sync; export http-handler; } \ No newline at end of file From 146d47ada68f5c8a2188b8a1a87c6a422855885b Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 27 Apr 2026 10:50:20 +0000 Subject: [PATCH 2/6] refactor: split cache.wit into cache-types.wit, cache.wit, cache-sync.wit Agent-Logs-Url: https://github.com/G-Core/FastEdge-wit/sessions/0af0496f-0733-4129-a737-89b73196b4c5 Co-authored-by: ruslanti <5754648+ruslanti@users.noreply.github.com> --- cache-sync.wit | 53 ++++++++++++++++++++++++++++++++++++ cache-types.wit | 15 +++++++++++ cache.wit | 72 +------------------------------------------------ 3 files changed, 69 insertions(+), 71 deletions(-) create mode 100644 cache-sync.wit create mode 100644 cache-types.wit diff --git a/cache-sync.wit b/cache-sync.wit new file mode 100644 index 0000000..f04346c --- /dev/null +++ b/cache-sync.wit @@ -0,0 +1,53 @@ +/// FastEdge cache interface (synchronous variant). +interface cache-sync { + use gcore:fastedge/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, 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) -> 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; + + /// 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; + + /// 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; +} diff --git a/cache-types.wit b/cache-types.wit new file mode 100644 index 0000000..287e71f --- /dev/null +++ b/cache-types.wit @@ -0,0 +1,15 @@ +/// Shared cache types for sync and async interfaces. +interface cache-types { + type payload = list; + + /// 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) + } +} diff --git a/cache.wit b/cache.wit index ad8df06..c520829 100644 --- a/cache.wit +++ b/cache.wit @@ -1,25 +1,9 @@ -/// Shared cache types for sync and async interfaces. -interface cache-types { - type payload = list; - - /// 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) - } -} - /// FastEdge cache interface (async variant). /// /// This keeps the original `cache` name for backward compatibility with /// existing async consumers. interface cache { - use cache-types.{payload, error}; + use gcore:fastedge/cache-types.{payload, error}; /// Get the value associated with `key`. /// @@ -70,57 +54,3 @@ interface cache { /// Returns `err(error)` if the operation fails. expire: async func(key: string, ttl-ms: u64) -> result; } - -/// 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, 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) -> 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; - - /// 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; - - /// 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; -} From 2e42fb34047fc822d63271926d15158a1284b3f3 Mon Sep 17 00:00:00 2001 From: Ruslan Pislari Date: Mon, 27 Apr 2026 15:24:23 +0300 Subject: [PATCH 3/6] fix: import of cache-types --- cache-sync.wit | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cache-sync.wit b/cache-sync.wit index f04346c..01e0d8e 100644 --- a/cache-sync.wit +++ b/cache-sync.wit @@ -1,6 +1,6 @@ /// FastEdge cache interface (synchronous variant). interface cache-sync { - use gcore:fastedge/cache-types.{payload, error}; + use cache-types.{payload, error}; /// Get the value associated with `key`. /// From b6fdc9f73f0e9023d7e4d1c720990fdf0d60e13a Mon Sep 17 00:00:00 2001 From: Ruslan Pislari Date: Mon, 27 Apr 2026 15:28:19 +0300 Subject: [PATCH 4/6] fix: import of cache-types --- cache.wit | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cache.wit b/cache.wit index c520829..77ba27a 100644 --- a/cache.wit +++ b/cache.wit @@ -3,7 +3,7 @@ /// This keeps the original `cache` name for backward compatibility with /// existing async consumers. interface cache { - use gcore:fastedge/cache-types.{payload, error}; + use cache-types.{payload, error}; /// Get the value associated with `key`. /// From 34cfcf63d22268320ec1365b50ae490e0ced8da4 Mon Sep 17 00:00:00 2001 From: Ruslan Pislari Date: Thu, 30 Apr 2026 14:48:45 +0300 Subject: [PATCH 5/6] fix: remove async cache interface --- cache.wit | 56 ------------------------------------------------------- world.wit | 1 - 2 files changed, 57 deletions(-) delete mode 100644 cache.wit diff --git a/cache.wit b/cache.wit deleted file mode 100644 index 77ba27a..0000000 --- a/cache.wit +++ /dev/null @@ -1,56 +0,0 @@ -/// FastEdge cache interface (async variant). -/// -/// This keeps the original `cache` name for backward compatibility with -/// existing async consumers. -interface cache { - 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: async func(key: string) -> result, 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: async func(key: string, value: payload, ttl-ms: option) -> 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: async 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: async func(key: string) -> result; - - /// 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: async func(key: string, delta: s64) -> result; - - /// 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: async func(key: string, ttl-ms: u64) -> result; -} diff --git a/world.wit b/world.wit index fb4969a..f319593 100644 --- a/world.wit +++ b/world.wit @@ -7,7 +7,6 @@ world reactor { import secret; import key-value; import utils; - import cache; import cache-sync; export http-handler; From ed3708a99b0bf0c4351a8287923bc0051da83b67 Mon Sep 17 00:00:00 2001 From: Ruslan Pislari Date: Thu, 30 Apr 2026 15:07:28 +0300 Subject: [PATCH 6/6] Update cache-types.wit Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- cache-types.wit | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cache-types.wit b/cache-types.wit index 287e71f..ea98bf8 100644 --- a/cache-types.wit +++ b/cache-types.wit @@ -1,4 +1,4 @@ -/// Shared cache types for sync and async interfaces. +/// Shared cache types for cache interfaces. interface cache-types { type payload = list;