Skip to content

feat(proxywasm): cache API - #86

Open
ruslanti wants to merge 5 commits into
mainfrom
feat/proxywasm-cache
Open

ruslanti wants to merge 5 commits into
mainfrom
feat/proxywasm-cache

Conversation

@ruslanti

Copy link
Copy Markdown
Collaborator

No description provided.

Implements the cache-sync WIT interface for ProxyWasm/CDN apps, mirroring
the existing key_value module. Free functions rather than a handle-based
Store, since the cache has no named stores — every operation is scoped to
the calling application and addressed by key alone.

- src/proxywasm/cache.rs: get, set, delete, exists, incr, expire, purge,
  purge_prefix, with an Error enum matching cache-types.error
- src/proxywasm/mod.rs: eight proxy_cache_* FFI declarations
- examples/cdn/cache: CDN example exercising all operations via query
  parameters, plus debugger fixtures
- docs: HOST_SDK_CONTRACT FFI table, examples README, plugin manifest
  entries, CHANGELOG decision log

The proxy_cache_* symbol names and signatures follow the proxy_kv_store_*
convention and still need confirming against the host implementation. The
example uses a path dependency until proxywasm::cache is published.
- Replace `panic!` with `Err(status)` for unexpected host statuses in `get` and `set` methods.
- Add comments to clarify behavior for unrecognized statuses.
@ruslanti ruslanti self-assigned this Sep 16, 2026
Copilot AI lite review requested due to automatic review settings September 16, 2026 08:00

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

Unconfirmed host ABI and unresolved critical doctest and integration issues require human review before approval.

Pull request overview

Adds ProxyWasm cache support, a CDN cache example with fixtures, and updated secret error handling and host-contract documentation.

Changes:

  • Adds cache FFI declarations and safe wrappers.
  • Adds CDN cache example documentation and test fixtures.
  • Updates manifests, status documentation, changelog, and secret handling.
File summaries
File Reviewed change Final review notes
src/proxywasm/secret.rs Returns unknown host statuses as errors. nit (1 vote): Regenerate docs/CDN_APPS.md after this public behavior change.
src/proxywasm/mod.rs Registers the cache module and FFI imports. critical (2 votes): Confirm the inferred host ABI and add a compatibility check. moderate (2 votes): Apply the required semver version bump. nit (1 vote): Regenerate cache API documentation.
src/proxywasm/cache.rs Implements the cache API wrappers. critical (1 vote): Default doctests reference undeclared proxy-wasm; mark them ignored or provide the dependency. Applies at lines 9 and 41.
fastedge-plugin-source/manifest.json Adds cache example mappings. moderate (2 votes): Required mappings target missing companion plugin files; defer them or land those files first.
examples/README.md Lists the cache example.
examples/cdn/cache/src/lib.rs Implements the query-based cache demonstration. nit (3 votes): The parser accepts zero as no expiry, but the error message rejects it. Update the message or reject zero at lines 138 and 204.
examples/cdn/cache/README.md Documents cache usage and APIs.
examples/cdn/cache/fixtures/no-query-params.test.json Adds the no-query-parameters test fixture.
examples/cdn/cache/fixtures/no-query-params.live.json Adds the no-query-parameters live fixture.
examples/cdn/cache/fixtures/invalid-action.test.json Adds the invalid-action test fixture.
examples/cdn/cache/fixtures/invalid-action.live.json Adds the invalid-action live fixture.
examples/cdn/cache/fixtures/cache-set.test.json Adds the cache-set test fixture.
examples/cdn/cache/fixtures/cache-set.live.json Adds the cache-set live fixture.
examples/cdn/cache/fixtures/cache-incr.test.json Adds the cache-increment test fixture.
examples/cdn/cache/fixtures/cache-incr.live.json Adds the cache-increment live fixture.
examples/cdn/cache/fixtures/cache-get.test.json Adds the cache-get test fixture.
examples/cdn/cache/fixtures/cache-get.live.json Adds the cache-get live fixture.
examples/cdn/cache/Cargo.toml Defines example dependencies. moderate (1 vote): The repository-relative dependency cannot resolve when generated as a scaffold or documentation pattern; defer registration or use a released version.
examples/cdn/cache/Cargo.lock Locks example dependencies.
context/reference/ERROR_CODES.md Documents cache errors and statuses. nit (1 vote): Broaden Other(String) to cover other host or implementation errors.
context/CHANGELOG.md Records cache implementation decisions and follow-ups.
context/architecture/HOST_SDK_CONTRACT.md Documents cache FFI contracts.
Review details

Suppressed comments (6)

context/reference/ERROR_CODES.md:80

  • Other(String) is described as only an unrecognized status, but the table immediately lists recognized host failures (3, 4, 6, 7, 8, and 12) and error_from_status maps all of them to this variant. Update the description to cover other host/implementation errors as well.
| `Other(String)` | Unrecognized host status code |

examples/cdn/cache/Cargo.toml:13

  • This file is registered as both a scaffold blueprint and a documentation pattern, so a copied/generated app cannot resolve the repository-relative ../../.. dependency. Keep the example out of those manifest entries until the cache API is published, or land it with a released fastedge version and update the lockfile.
fastedge = { path = "../../..", features = ["proxywasm"] }

examples/cdn/cache/src/lib.rs:204

  • The parser accepts 0, but this message says the value must be positive; that is inconsistent with the cache TTL contract and the u64 input. Say non-negative, or explicitly reject zero before calling cache::expire.
            .map_err(|_| "Invalid 'ttl' value: must be a positive number of milliseconds".to_string())?;

src/proxywasm/cache.rs:41

  • The rustdoc example contains Action::Pa§use, so the example cannot be parsed or compiled as written. Replace the invalid identifier with Action::Pause so the public usage example is valid.
//!             return Action::Pa§use;

src/proxywasm/mod.rs:32

  • Adding pub mod cache exposes a new public fastedge::proxywasm::cache API, but docs/CDN_APPS.md still documents only the existing ProxyWasm services and has no cache API section. Run ./fastedge-plugin-source/generate-docs.sh (or update its generation source) in this PR so the generated consumer documentation matches the crate.
pub mod cache;

src/proxywasm/secret.rs:82

  • This changes the public secret wrapper so previously panicking host statuses are returned as errors, but docs/CDN_APPS.md was not regenerated in the PR. Run ./fastedge-plugin-source/generate-docs.sh so the generated public API documentation is refreshed after this behavior change.
            status => Err(status),
  • Files reviewed: 21/22 changed files
  • Comments generated: 6
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/proxywasm/cache.rs
Comment thread src/proxywasm/mod.rs
Comment thread fastedge-plugin-source/manifest.json
Comment thread src/proxywasm/mod.rs
Comment thread examples/cdn/cache/src/lib.rs
Comment thread src/proxywasm/cache.rs
…se format

- Updated README to provide detailed instructions for using the Key Value CDN example.
- Added query examples for all supported actions (`get`, `scan`, `zrange`, `zscan`, `bfExists`).
- Documented request requirements, response format, and error handling.
- Updated `get_property` method for compatibility (`["request.query"]`).
@ruslanti ruslanti changed the title Feat/proxywasm cache feat(proxywasm): cache API Sep 16, 2026
- Added documentation for the new `fastedge::proxywasm::cache` module, including function definitions, error handling, and usage examples.
- Updated `generate-docs.sh` to include cache module source files in the CDN_APPS docs generation process.
- Refined tier descriptions to include cache usage alongside KV, secrets, and dictionary.
- Fixed formatting inconsistencies in tables for better readability.
@ruslanti
ruslanti requested a lite review from Copilot September 16, 2026 09:23
@ruslanti ruslanti added the enhancement New feature or request label Sep 16, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

Unresolved critical and moderate findings remain around consumer builds, status encoding, release metadata, and FFI ABI verification.

Review details

Suppressed comments (7)

examples/cdn/cache/src/lib.rs:138

  • This message says ttl=0 is invalid, but the code accepts zero and the wrapper explicitly uses zero to mean no expiry for set. Report the accepted non-negative range instead of claiming the value must be positive.
                    .map_err(|_| "Invalid 'ttl' value: must be a positive number of milliseconds".to_string())?,

examples/cdn/cache/src/lib.rs:204

  • The parser accepts ttl=0, so this error text is also inaccurate for expire; zero is a valid u64 TTL input even if the host gives it immediate-expiry semantics. Either validate zero explicitly or describe the accepted value as non-negative.
            .map_err(|_| "Invalid 'ttl' value: must be a positive number of milliseconds".to_string())?;

fastedge-plugin-source/generate-docs.sh:92

  • The script now supplies the cache sources, but fastedge-plugin-source/.generation-config.md still omits the cache module from the CDN_APPS source/required-content instructions and comparison table. Future regeneration is therefore not specified to retain or validate this new public section; update the generator config and regenerate docs/CDN_APPS.md.
SOURCE_FILES[CDN_APPS.md]="src/proxywasm/mod.rs src/proxywasm/cache.rs src/proxywasm/key_value.rs src/proxywasm/secret.rs src/proxywasm/dictionary.rs src/proxywasm/utils.rs examples/cdn/hello_world/src/lib.rs examples/cdn/hello_world/Cargo.toml examples/cdn/custom/src/lib.rs examples/cdn/custom/Cargo.toml examples/cdn/jwt/src/lib.rs examples/cdn/jwt/Cargo.toml examples/cdn/key_value/src/lib.rs examples/cdn/key_value/Cargo.toml examples/cdn/cache/src/lib.rs examples/cdn/cache/Cargo.toml examples/cdn/geoblock/src/lib.rs examples/cdn/geoblock/Cargo.toml examples/cdn/variables_and_secrets/src/lib.rs examples/cdn/variables_and_secrets/Cargo.toml"

fastedge-plugin-source/manifest.json:936

  • These required mappings target cache-rust.md and examples-cache-rust.md, but the PR does not add the matching plugin intent/reference files; the changelog explicitly records that they are still missing. The next plugin sync will fail until the companion files exist, so coordinate that change before enabling these required entries.
    "cdn-cache-blueprint": {
      "reference_file": "plugins/gcore-fastedge/skills/scaffold/reference/cdn/cache-rust.md",
      "section": null
    },
    "cdn-cache-pattern": {
      "reference_file": "plugins/gcore-fastedge/skills/fastedge-docs/reference/cdn/examples-cache-rust.md",

src/proxywasm/mod.rs:32

  • Adding pub mod cache expands the published public API, but the workspace package is still version 0.4.2. This additive API needs a semver-minor version bump and matching release metadata before consumers can depend on it; otherwise it is only available from a source checkout.
pub mod cache;

src/proxywasm/mod.rs:112

  • The PR's own changelog says these proxy_cache_* symbols and signatures are derived and still need confirmation. Because these are raw Wasm imports, a wrong name prevents instantiation and a wrong pointer/type ABI can corrupt memory; verify them against the host implementation before publishing this module.
    fn proxy_cache_get(
        key_data: *const u8,
        key_size: usize,
        return_value_data: *mut *mut u8,
        return_value_size: *mut usize,

src/proxywasm/secret.rs:82

  • Changing both secret wrappers from panicking on unknown host statuses to returning Err changes public behavior, but the generated docs/HOST_SERVICES.md is not updated. Its generator explicitly consumes src/proxywasm/secret.rs; run ./fastedge-plugin-source/generate-docs.sh and commit the regenerated output.
            status => Err(status),
  • Files reviewed: 25/26 changed files
  • Comments generated: 3
  • Review effort level: Lite


[dependencies]
proxy-wasm = "0.2"
fastedge = { path = "../../..", features = ["proxywasm"] }
Comment thread examples/cdn/cache/src/lib.rs
Comment thread src/proxywasm/cache.rs Outdated
… path

- Fixed a typo in `cache.rs` (`Pa§use` to `Pause`) in error handling logic.
- Standardized property path format in `send_error` function for CDN examples (`response.status` instead of `response`, `status`).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants