Is there an existing issue for this?
Description
The runtime now exposes the newer per-Worker Workers Cache (announcement: https://blog.cloudflare.com/workers-cache/, docs: https://developers.cloudflare.com/workers/cache/), which is driven by Cache-Control / Cache-Tag response headers and has one imperative API: ctx.cache.purge() (also available as the cache export of cloudflare:workers). This is distinct from the Service-Worker Cache API already covered by worker::Cache (caches.default).
There's currently no way to call purge from Rust — worker::Context doesn't expose ctx.cache, and worker-sys has no binding for the CacheContext object. I'd like to add bindings for it.
Proposed API:
use worker::CachePurgeOptions;
// From the execution context (mirrors JS `ctx.cache`)
if let Some(cache) = ctx.cache() {
let result = cache.purge(CachePurgeOptions::tags(["blog-posts"])).await?;
if !result.success {
console_error!("purge failed: {:?}", result.errors);
}
}
// Or without a `ctx` in scope, via the `cloudflare:workers` export
let cache = worker::cache();
cache.purge(CachePurgeOptions::everything()).await?;
Shape of the types:
Context::cache() -> Option<CacheContext> — None when the feature isn't enabled or the runtime predates it.
worker::cache() -> CacheContext — the cloudflare:workers module export, for code with no ctx in scope.
CachePurgeOptions with constructors tags(...), path_prefixes(...), and everything(), serialized to the runtime's camelCase keys (tags, pathPrefixes, purgeEverything). purge_everything is validated as mutually exclusive with the other two before crossing the FFI boundary.
CachePurgeResult { success: bool, errors: Vec<CachePurgeError> } mirroring the runtime's result object; a rejected promise (e.g. permission error) surfaces as Err.
Is there an existing issue for this?
Description
The runtime now exposes the newer per-Worker Workers Cache (announcement: https://blog.cloudflare.com/workers-cache/, docs: https://developers.cloudflare.com/workers/cache/), which is driven by
Cache-Control/Cache-Tagresponse headers and has one imperative API:ctx.cache.purge()(also available as thecacheexport ofcloudflare:workers). This is distinct from the Service-Worker Cache API already covered byworker::Cache(caches.default).There's currently no way to call
purgefrom Rust —worker::Contextdoesn't exposectx.cache, andworker-syshas no binding for theCacheContextobject. I'd like to add bindings for it.Proposed API:
Shape of the types:
Context::cache() -> Option<CacheContext>—Nonewhen the feature isn't enabled or the runtime predates it.worker::cache() -> CacheContext— thecloudflare:workersmodule export, for code with noctxin scope.CachePurgeOptionswith constructorstags(...),path_prefixes(...), andeverything(), serialized to the runtime's camelCase keys (tags,pathPrefixes,purgeEverything).purge_everythingis validated as mutually exclusive with the other two before crossing the FFI boundary.CachePurgeResult { success: bool, errors: Vec<CachePurgeError> }mirroring the runtime's result object; a rejected promise (e.g. permission error) surfaces asErr.