@ehmpathy/simple-dynamodb-cache
TypeScript icon, indicating that this package has built-in type declarations

1.0.4 • Public • Published

simple-dynamodb-cache

A simple dynamodb cache with time based expiration policies

features

install

npm install simple-dynamodb-cache

use

create a dynamodb table

as you'd expect, this cache persists to dynamodb, so you'll need to define a table it can use

this library expects that the dynamodb table it'll be given has the following attributes

  • partitionKey = p
  • ttlKey = t

here's a terraform example for creating a table with this schema

resource "aws_dynamodb_table" "table_domain_driven_cache" {
  name         = "infrastructure-${var.environment}-table-domain-driven-cache"
  billing_mode = "PAY_PER_REQUEST"
  point_in_time_recovery {
    enabled = var.environment == "prod" ? true : false
  }

  hash_key = "p" # partition key
  ttl {
    enabled        = true
    attribute_name = "t" # ttl key
  }

  attribute {
    name = "p"
    type = "S"
  }
}

create a cache

const cache = createCache({ table: 'svc-raindrops-prod-cache' });

set to the cache

await cache.set('answer', '42');

ℹ️ note: if you'd like an item to never expire, set the expiration time to Infinity

get from the cache

await cache.get('answer'); // '42'

Package Sidebar

Install

npm i @ehmpathy/simple-dynamodb-cache

Weekly Downloads

10

Version

1.0.4

License

none

Unpacked Size

21.2 kB

Total Files

12

Last publish

Collaborators

  • uladkasach