@temporalio/common
v1.25.0
Published
Common library for code that's used across the Client, Worker, and/or Workflow
Readme
@temporalio/common
Part of Temporal's TypeScript SDK (see docs and samples).
Common library for code that's used across the Client, Worker, and/or Workflow:
Payload Caching
Experimental. Clients and Workers can cache External Storage payloads, so a payload already in the cache is not retrieved from its storage driver again. Caching is off by default. The SDK exposes a generic PayloadCache interface and an in-memory implementation, InMemoryPayloadCache, exported from @temporalio/client and @temporalio/worker. Pass a payload cache to clients and workers to enable caching, or pass the same cache to both to share it:
import { Client, InMemoryPayloadCache } from '@temporalio/client';
import { Worker } from '@temporalio/worker';
const payloadCache = new InMemoryPayloadCache({
maxTotalBytes: 128 * 1024 * 1024,
maxEntries: 20_000,
});
const client = new Client({ payloadCache });
const worker = await Worker.create({ taskQueue, workflowsPath, payloadCache });n.b. The cache is a best-effort optimization.
External Storage
External Storage caches the final encoded Payload given to a storage driver. Cache hits do not call the storage driver. The reference payload claim data is used to construct the cache key through the following steps:
- UTF-8 encode the driver name and every claim key and value without normalization.
- Sort claim keys by unsigned lexicographic order of their UTF-8 bytes.
- Encode each string as its ASCII base-10 UTF-8 byte length,
:, then the original string. - Prefix the key with
v0/temporal/extstore/. - Concatenate the encoded driver name, then each sorted claim key and value.
For driver aws-s3 and claim data { bucket: "abc", key: "1" }, the key is:
v0/temporal/extstore/6:aws-s36:bucket3:abc3:key1:1