npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@defra/catbox-dynamodb

v0.7.1

Published

A hapi plugin for providing a hapi/catbox dynamodb engine

Readme

@defra/catbox-dynamodb

A Catbox compatible caching engine that uses Amazon DynamoDB as the backing store.

Installation

npm install @defra/catbox-dynamodb

Usage

Standalone

import { CatboxDynamoDB } from '@defra/catbox-dynamodb'

const engine = new CatboxDynamoDB({
  tableName: 'my-cache-table',
  ttl: 60000, // optional, defaults to 1 hour
  clientOptions: { region: 'eu-west-2' },
  logger
})

await engine.start()
const ready = await engine.isReady()

With hapi Catbox

This engine can be plugged into hapi’s Catbox cache system.

import Hapi from '@hapi/hapi'
import Catbox from '@hapi/catbox'
import { CatboxDynamoDB } from '@defra/catbox-dynamodb'

const server = Hapi.server({
  port: 3000,
  cache: [
    {
      name: 'session',
      provider: {
        constructor: CatboxDynamoDB,
        options: {
          tableName: 'test-session-cache',
          ttl: 60 * 1000,
          clientOptions: {
            endpoint: 'http://127.0.0.1:4566', // localstack endpoint
            region: 'eu-west-2'
          },
          logger
        }
      }
    }
  ]
})

// Example route using the session cache
server.route({
  method: 'GET',
  path: '/',
  handler: async (request, h) => {
    const cache = server.cache({ cache: 'session', segment: 'sessions' })
    const key = 'user:123'
    const cached = await cache.get(key)
    if (!cached) {
      await cache.set(key, { name: 'Alice' }, 60000)
      return 'New session cached'
    }
    return `Session restored for ${cached.name}`
  }
})

await server.start()

Configuration Example

A config-driven setup can select the cache backend (DynamoDB, Redis, or memory). Example:

if (engine === 'dynamodb') {
  return new CatboxDynamoDB({
    tableName: config.get('dynamoDb.tableName'),
    ttl: config.get('session.cache.ttl'),
    clientOptions: {
      endpoint: config.get('dynamoDbEndpoint'),
      region: config.get('awsRegion')
    },
    logger
  })
}

This works with LocalStack by pointing the DynamoDB client to the LocalStack endpoint.

DynamoDB Table Schema

Your DynamoDB table must have a primary key named id of type String. The engine manages these attributes:

  • value (String) stores the serialized cache entry
  • timestamp (Number) stores the insertion timestamp in milliseconds
  • expiresAt (Number) stores the absolute expiration time in milliseconds

Expired items remain in the table until overwritten or deleted, but the engine will not return them when retrieved. A TTL should be set up on expiresAt on the dynamoDB table to clear these entries.

LocalStack Setup

The following commands will create a DynamoDB table and enable TTL on the expiresAt field using LocalStack:

aws --endpoint http://localhost:4566 dynamodb create-table \
  --region eu-west-2 \
  --table-name test-session-cache \
  --attribute-definitions AttributeName=id,AttributeType=S \
  --key-schema AttributeName=id,KeyType=HASH \
  --provisioned-throughput ReadCapacityUnits=1,WriteCapacityUnits=1

aws --endpoint http://localhost:4566 dynamodb update-time-to-live \
  --region eu-west-2 \
  --table-name test-session-cache \
  --time-to-live-specification "Enabled=true,AttributeName=expiresAt"