CachePuppy
Quick start

JavaScript quick start

Connect with createClient, subscribe and publish, then set and get cache data.

Add the SDK

Install @cachepuppy/core the way your team distributes it (private npm registry, tarball, git URL, or a vendored build). The snippets below assume you can import from "@cachepuppy/core" in your bundler or Node project.

Building from a git checkout

If you are working inside the CachePuppy repository itself, build the package under sdk/javascript (npm ci && npm run build) and point your app at the local dist output or a file: dependency — same import path.

Minimal example

Point at the websocket URL from Run with Docker: ws://localhost:4000/socket/websocket.

import { createClient } from "@cachepuppy/core";

const client = createClient({
  url: "ws://localhost:4000/socket/websocket",
});

await client.connect();

// Realtime topics: subscribe and publish logical topic "orders"
const off = await client.subscribe("orders", (message) => {
  console.log("message", message);
});
await client.publish("orders", "created", { orderId: "o1" });

// Distributed cache via the session channel (same semantics as HTTP /api/cache/*)
await client.setData("demo", "greeting", { text: "hello" }, { ttlMs: 60_000 });
const value = await client.getData("demo", "greeting");
await client.updateData("demo", "greeting", { text: "hi" });
console.log("cached value", value);

off();
await client.disconnect();

Next steps

On this page