Skip to main content
HydroGo
FrontendsCaching and webhooks

Caching and webhooks

Keep the API fast with shared caching, and notify other systems when content changes.

Caching strategy

Zero build on publish does not mean zero caching. Put a short cache between visitors and HydroGo and let freshness be a number you choose.

LayerSettingEffect
Your frontend responsecache-control: public, max-age=0, s-maxage=30, stale-while-revalidate=60A CDN serves a response for 30 s, then refreshes in the background. Edits appear within about half a minute.
Sitemaps-maxage=300Crawlers rarely need fresher data.
MediaLong cache lifetime at your CDNMedia objects are immutable: a replaced file gets a new id, so old URLs stay valid.
Previews and adminprivate, no-storeNever cache.
TS
// SvelteKit load function
export async function load({ setHeaders }) {
  const news = await hydro.listNews('en', 10);
  setHeaders({ 'cache-control': 'public, max-age=0, s-maxage=30, stale-while-revalidate=60' });
  return { news };
}
Need instant updates for a specific page? Skip the cache for it, or purge the CDN from a webhook (below).

Webhooks

HydroGo can POST signed JSON events to your systems when content changes, for example to purge a CDN, trigger a static rebuild or notify a chat room. Internally, transactional outbox events (such as content.updated and site.updated) are mapped to the external webhook topics below (such as page.* and news.*).

config.yaml
webhooks:
  - id: frontend
    url: https://ci.example.com/hooks/hydrogo
    topics: [page.published, news.published, news.retracted]
BASH
# the secret never lives in YAML; it is read from the environment
HYDRO_WEBHOOK_SECRET=change-me
# shortcut for a single endpoint without any YAML
HYDRO_WEBHOOK_URL=https://ci.example.com/hooks/hydrogo
HYDRO_WEBHOOK_TOPICS=page.published,news.published,news.retracted
TopicFires when
page.created, page.updated, page.publishedA page changes or is published.
news.created, news.updated, news.scheduled, news.published, news.retractedThe news lifecycle.
user.invitedA staff invitation is created (contains personal data and is only sent to endpoints with allow_pii: true).
order.created, tenant.provisionedCommerce and tenancy events.

List the exact catalog your binary supports with hydro events catalog.

Event payload

JSON
{
  "id": "evt_01",
  "topic": "news.published",
  "aggregate_id": "art_42",
  "payload_version": 1,
  "data": { }
}

Verify the signature

Each request carries X-Hydro-Event, X-Hydro-Timestamp, X-Hydro-Signature and an Idempotency-Key (the event id). The signature is sha256= followed by the hex HMAC-SHA256 of <timestamp>.<raw body> using your secret. Reject requests with an old timestamp and de-duplicate by Idempotency-Key; deliveries are retried on failure.

TS
import { createHmac, timingSafeEqual } from 'node:crypto';

export function verify(rawBody: string, headers: Headers, secret: string): boolean {
  const ts = headers.get('x-hydro-timestamp') ?? '';
  const sig = headers.get('x-hydro-signature') ?? '';
  if (Math.abs(Date.now() / 1000 - Number(ts)) > 300) return false;
  const expected = 'sha256=' + createHmac('sha256', secret).update(`${ts}.${rawBody}`).digest('hex');
  const a = Buffer.from(sig);
  const b = Buffer.from(expected);
  return a.length === b.length && timingSafeEqual(a, b);
}

Static frontends

If you deliberately use a static site generator, point a webhook at your CI provider's build trigger and subscribe to page.published, news.published and news.retracted. This is an option for your frontend, not a requirement of HydroGo: server rendering with a short cache avoids rebuilds entirely.

Webhook URLs must be plain http or https URLs without embedded credentials, and redirects are validated again. Use HTTPS and always verify the signature.