On this page
Overview
Provides a narrow exact-key JSON cache inside one app-owned OPFS namespace.
- Artifact
ScopedOPFSCache.js· esm - Classification
public first party - Availability
Browser / native WebView - Normalization
Filename-safe scope and key segments, complete JSON values, and malformed-cache cleanup are normalized; storage errors remain mixed.
Import and lifecycle
import scopedOpfsCache from '/arcane/modules/ScopedOPFSCache.js';
Construction validates scope/support only. The first operation lazily opens/creates the application data directory and namespace. set() writes one complete JSON file; get() parses the complete file and removes malformed JSON; delete() is exact-key and idempotent. There is no enumeration or clear-all.
Application-facing behavior: default ScopedOPFSCache; support check and get/set/delete APIs.
Protocol and host implementation
OPFS + AppDataScope This detail does not widen the application-facing API or grant authority.
Exports, signatures, parameters, and results
| Binding | Form | Declaration or signature | Parameter syntax |
|---|---|---|---|
default | default · class | class ScopedOPFSCache | — |
| Member | Kind | Exact public declaration | Parameter syntax |
|---|---|---|---|
ScopedOPFSCache.constructor | constructor | constructor({
applicationId=null,
namespace,
storage=globalThis.navigator?.storage,
documentObject=globalThis.document,
arcane=globalThis.Arcane
}={}) | {
applicationId=null,
namespace,
storage=globalThis.navigator?.storage,
documentObject=globalThis.document,
arcane=globalThis.Arcane
}={} |
ScopedOPFSCache.supported | static method | static supported(storage=globalThis.navigator?.storage) | storage=globalThis.navigator?.storage |
ScopedOPFSCache.namespace | get | get namespace() | — |
ScopedOPFSCache.applicationId | get | get applicationId() | — |
ScopedOPFSCache.get | async method | async get(key) | key |
ScopedOPFSCache.set | async method | async set(key,value) | key,value |
ScopedOPFSCache.delete | async method | async delete(key) | key |
Parameter meanings and results
new ScopedOPFSCache({applicationId?,namespace,storage?,documentObject?,arcane?}); static supported(storage?); getters namespace/applicationId; get(key) resolves the complete JSON value or undefined; set(key,JSONValue) resolves the same value; delete(key) resolves boolean.
Events, side effects, and errors
Source-literal CustomEvent dispatches
No source-literal CustomEvent dispatch is part of this artifact.
Lifecycle and event flow
This artifact has no additional documented lifecycle event flow.
Direct coded failures
OPFS_UNAVAILABLE
Exported Error subclasses
This artifact exports no Error subclass.
Documented failure behavior
- OPFS_UNAVAILABLE
- TypeError or RangeError for an unsafe segment or nonserializable value.
- Malformed cached JSON is invalid, removed, and returned as undefined.
- Underlying OPFS failures are preserved.
Availability and capabilities
Browser / native WebView. Filename-safe scope and key segments, complete JSON values, and malformed-cache cleanup are normalized; storage errors remain mixed.
OPFS needs no Core capability; omitted applicationId may use capability-free app.current to bind application ownership.
Contract example
import ScopedOPFSCache from '/arcane/modules/ScopedOPFSCache.js';
if (ScopedOPFSCache.supported()) {
const cache = new ScopedOPFSCache({namespace:'example-cache'});
await cache.set('welcome.json',{ready:true});
console.log(await cache.get('welcome.json'));
}
Related reference
No direct Core call is claimed for this artifact. Any injected provider or consuming module retains its own documented authority.