1.0.4 • Published 7 months ago

@ehmpathy/simple-dynamodb-cache v1.0.4

Weekly downloads
-
License
-
Repository
github
Last release
7 months ago

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'
1.0.4

7 months ago

1.0.3

9 months ago

1.0.2

9 months ago

1.0.1

9 months ago