@ryands17/ddb-cache
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

DynamoDB as cache

A full serverless cache for DynamoDB that uses ElectroDB under the hood for querying and TTL management.

Prerequisites

  • PNPM
  • Docker (to run tests)

This library also requires a DynamoDB table to be created with the following required fields:

  • pk: String (HASH key)
  • sk: String (SORT key)
  • ttl: Number (DynamoDB TTL field)

Scripts

  • pnpm test: Run all tests
  • pnpm build: Build the lib for CJS and ESM

Usage

Setup a DynamoDB table with the above fields (pk, sk and ttl). Then create an instance of the cache as follows:

const client = new DynamoDBClient();
// pass in the client, table name, namespace (optional) and TTL in seconds (optional)
const cache = new DynamoDBCache(client, 'cache-table-name', 'my-app-name', 60);

To set an item on the cache, use:

await cache.set('keyName', 'value');

To fetch an item, use:

const value = await cache.get('keyName');

The other methods are:

await cache.delete('keyName');

const isKeyPreset: boolean = await cache.has('keyName');

// clear all values from a namespace
await cache.clear('my-app-name');

Readme

Keywords

Package Sidebar

Install

npm i @ryands17/ddb-cache

Weekly Downloads

4

Version

1.0.1

License

none

Unpacked Size

3.62 kB

Total Files

3

Last publish

Collaborators

  • ryands17