artifact-cache

A shared cache for results computed by registered web applications. Anyone can read; writing requires the app's passcode.

A registered app looks up a key (usually a hash of its inputs). On a miss, it computes the result, and if the user has entered the app's passcode, it stores the result so that later visitors get the cached copy.

Client

import { ArtifactCache } from "https://artifact-cache.tempory.net/client.js";

const cache = new ArtifactCache({ appId: "my-app" });
const key = await ArtifactCache.hashKey({ version: 1, params });

let result = await cache.getJSON(key);
if (result === null) {
  result = await compute(params);
  if (cache.canWrite()) await cache.putJSON(key, result);
}

// once, e.g. from a settings box:
cache.setPasscode(passcodeFromUser);          // kept in localStorage
const { valid } = await cache.checkPasscode();

Other methods: get (returns a Response or null), getText, getArrayBuffer, getMeta, exists, put(key, data, { contentType, meta }), delete, url(key).

HTTP API

RequestNotes
GET /api/apps/:app/entries/:keyData. Supports Range and If-None-Match. 404 if not cached.
HEAD /api/apps/:app/entries/:keyExistence and size.
GET /api/apps/:app/meta/:keyJSON metadata: size, content type, created/updated times, optional app metadata.
PUT /api/apps/:app/entries/:keyStore or replace. Headers: X-Passcode, Content-Type, optional X-Artifact-Meta (URI-encoded JSON, at most 4 KB). Max 100 MB.
DELETE /api/apps/:app/entries/:keyRequires X-Passcode.
POST /api/apps/:app/check-passcodeReturns { valid, reason? }.

Keys are up to 512 characters of A-Z a-z 0-9 . _ -, optionally separated by /. Writes must also come from an origin registered for the app. Reads are allowed from any origin.

Admin