# Mantle Cloud public HTML cache

Start with the Recipes example packaged with your project's installed `@aotter/mantle` version. `get_site` identifies the installed example path in `guidance.docs.publicationExample.installedPath`. Use that example for the article model, publishing and withdrawal workflow.

## Declare the URL's access

Add `.mantle/access-routes.json` to new sites and to existing sites preparing for managed access. Within each site, list permanent anonymous paths in `public` and customer paths in `customer`. A pattern such as `/articles/*` includes the children of `/articles`. List `/articles` separately if it is public. Customer routes require an Access customer session before the Worker receives the request.

Choose a guarded route when an article must become staff-only at the same URL. Bind it to an eligible read-only Admin View. An explicit Access staff grant governs the private View.

```json
{
  "public": ["/", "/about"],
  "customer": ["/account"],
  "pages": [
    { "path": "/briefing", "target": "view:briefing", "publicWhenPublished": true }
  ]
}
```

Permanent anonymous pages can use the direct CDN cache. For a guarded page, Access reads the current release and publication before it looks up cached content. The response to the browser uses `private, no-store`. The `X-Mantle-Content-Cache` header reports a verified `MISS` or `HIT` on its public rendering. After Cloud accepts a withdrawal with `pages: []`, the next request uses staff access even if cache eviction is still pending. Publish the guarded paths from the new release when a release changes.

Keep guarded URLs in the `pages` class. Access rejects reuse of a URL across permanent-public and guarded classes.

Path-only registration lets Access share the HTML from your site's existing article SSR with anonymous and signed-in readers. On an edge miss, Access makes a fresh GET for the registered path, without browser cookies, authorization, visitor headers or caller identity. Keep your existing layout, Markdown, SEO and browser asset links in SSR.

Register only articles whose SSR reads published public data. Reads that require a user fail anonymously. Optional user data is absent. Load saved state, account menus and editing controls after the page loads through authenticated `no-store` endpoints. Keep drafts, previews, APIs and other routes out of registration.

For shared SSR, explicitly return `Cache-Control: public` on the anonymous public article response. Access requires HTML 200 without `Set-Cookie`, `private`, `no-store`, `no-cache`, or other `Vary` fields beyond `Host` and `Accept-Encoding`. Requests use ordinary site routing when the anonymous response declines sharing or uses a per-response CSP nonce. Older projections with `title` and `text` still use the isolated renderer. To move one to SSR, return `public` and register its path only with a higher revision.

## Cache a homepage and its aliases

Register `/` the same way as any other published page. On a site that enforces managed routes, declare the homepage and its public aliases in `.mantle/access-routes.json`. A registered, query-free alias can return a `301` or `308` (Access drops its body) with `Cache-Control: public` and a same-host public destination without query parameters or a fragment. Guarded pages continue to use the HTML-only cache path.

A registered `/` serves the anonymous homepage to signed-in members too. Load member-specific parts of the homepage after the page loads through an authenticated `no-store` endpoint.

A registration can set a shorter TTL for a frequently edited page, such as `{ "path": "/", "ttlSeconds": 300 }` in `pages`. The applied value is the lowest of that limit, the site TTL and the remaining serving entitlement. Increase the scope revision when the registration changes.

## Cache individual article paths

Commit `.mantle/cache.json` and publish the site.

```json
{"publicHtmlCache":"path"}
```

Omit the file or set `off` to turn caching off. For `path` or `group`, set the site's optional `publicHtmlTtlSeconds` to an integer from 1 to 604800 (7 days). Omit it to use 86400 (24 hours).

```json
{"publicHtmlCache":"group","publicHtmlTtlSeconds":259200}
```

A coding agent can commit this file through Cloud MCP `push_files` with the current head as `parent`. Native CI validates it and applies it when that release becomes active. Match the push operation and commit in `get_site` and check `deployment.activeVersion.publicHtmlTtlSeconds`. The value is the release's edge TTL limit. Cache admission can shorten it to the remaining serving entitlement, and content updates and deploys still clear the applicable cached HTML. Browsers continue to revalidate public HTML, and guarded pages keep their private browser policy.

`get_site` also reports the active mode and the release's initial purge outcome.

After the content transaction commits and the new version is readable by SSR, send the current published paths through the site's existing `MANTLE_SITES` binding. Use the exact public URL path as the key. Increase the scope revision on every published content change, including edits that keep the same path.

```ts
async function syncPublicHtml(binding: Fetcher, changes: unknown) {
  try {
    const response = await binding.fetch("https://internal/.mantle/public-html", {
      method: "POST",
      headers: { "content-type": "application/json" },
      body: JSON.stringify(changes),
    });
    const detail = await response.json();
    return response.ok ? detail : { status: "failed", detail };
  } catch {
    return { status: "failed", code: "public_html_sync_unavailable" };
  }
}

const path = "/en/recipes/noodles";
const cache = await syncPublicHtml(env.MANTLE_SITES, [{
  key: path,
  revision: 5,
  pages: [{ path }],
}]);
return { publication: contentResult, cache };
```

On withdrawal, send the same key with an increased revision and `pages: []`. When a slug changes, send the withdrawal for the old path and the new path together. Retries use the same revision and paths.

Return the committed article operation separately from the cache result. A successful cache result includes `scope`, `keys` and `purge`. `purge: "pending"` means Cloud saved the path registration and will retry eviction. Until a retry succeeds, a copy already at the edge can stay for the applied TTL, up to the site TTL (at most 7 days). This is an accepted risk; use a short TTL for content that may need to be taken down quickly. If the sync itself fails, report that failure alongside the successful content operation. Describe the automatic path or group refresh in the site's Access MCP publishing tool.

## Refresh a whole multilingual article

Set `publicHtmlCache` to `group` and publish the site. Use a stable key such as `recipe:42` for the language editions of one recipe. Send the complete published group and its new revision together.

```ts
const en = "/en/recipes/noodles", zh = "/zh-TW/recipes/mian";
const cache = await syncPublicHtml(env.MANTLE_SITES, [{
  key: "recipe:42",
  revision: 6,
  pages: [{ path: en }, { path: zh }],
}]);
```

When adding or withdrawing an edition, update the remaining pages' alternate links and increase the group revision. Send an empty `pages` list to withdraw the entire group. When a page moves between groups, include both groups in the update. Cloud scopes eviction to this site and group while each URL keeps its own cache entry.

After enabling or changing modes, register the paths from current published content. Unregistered URLs follow normal Access routing.

## Deploy with browser assets

Use the normal SSR asset links from your build. A code release clears the site's public HTML so new visitors get HTML with the current release's asset URLs. A previously open tab can reload if one of its old asset URLs disappeared.
