Skip to main content

Setting Up Caches

Caches allow you to locally store and reuse values from repeated events—such as API calls, database reads, or event publishing. This helps reduce the overhead of making remote calls during execution.

Creating a Cache

To create a new cache entry, use the create function from the product.cache interface:

import ductape from './ductapeClient';
import { IProductCache } from 'ductape-sdk/dist/types';

const details: IProductCache = {
name: 'Example Cache', // Name of the cache
description: 'Stores temporary API responses', // Description of what it stores
tag: 'example_cache', // Unique cache identifier
expiry: 60000 // Expiry time in milliseconds
};

await ductape.product.cache.create(details);
FieldTypeDescription
namestringThe name of the cache entry.
descriptionstringA short description of what the cache is used for.
tagstringA unique identifier for the cache entry.
expirynumber (milliseconds)The expiration time before the cache becomes invalid.

Updating a Cache

To update an existing cache entry, use the update function. Provide the tag of the cache you want to update and the new data:

const tag = 'example_cache';
const data: Partial<IProductCache> = {
name: 'Updated Cache Name',
description: 'Updated cache description',
expiry: 120000
};

await ductape.product.cache.update(tag, data);

All fields in the update payload are optional.

Fetching Caches

To retrieve all cache entries:

const caches = await ductape.product.cache.fetchAll();

This returns an array of all caches associated with your product.

To fetch a specific cache by its tag:

const tag = 'example_cache';
const cache = await ductape.product.cache.fetch(tag);

This returns the cache entry associated with the given tag.