{"id":23438550,"url":"https://github.com/simple-dev-tools/dynamodb-as-cache","last_synced_at":"2026-03-06T02:06:22.277Z","repository":{"id":57217819,"uuid":"365523994","full_name":"simple-dev-tools/dynamodb-as-cache","owner":"simple-dev-tools","description":"Use DynamoDB as cache service, providing Redis-like APIs and reducing the boilerplate of dealing low-level DynamoDB APIs.","archived":false,"fork":false,"pushed_at":"2021-12-05T07:44:34.000Z","size":84,"stargazers_count":3,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-15T11:48:45.202Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/simple-dev-tools.png","metadata":{"files":{"readme":"README.md","changelog":"Changelog.md","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-05-08T13:40:41.000Z","updated_at":"2024-12-29T09:56:28.000Z","dependencies_parsed_at":"2022-08-28T21:40:38.944Z","dependency_job_id":null,"html_url":"https://github.com/simple-dev-tools/dynamodb-as-cache","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simple-dev-tools%2Fdynamodb-as-cache","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simple-dev-tools%2Fdynamodb-as-cache/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simple-dev-tools%2Fdynamodb-as-cache/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simple-dev-tools%2Fdynamodb-as-cache/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/simple-dev-tools","download_url":"https://codeload.github.com/simple-dev-tools/dynamodb-as-cache/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248097979,"owners_count":21047346,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-12-23T14:50:01.365Z","updated_at":"2026-03-06T02:06:17.243Z","avatar_url":"https://github.com/simple-dev-tools.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![NPM](https://nodei.co/npm/dynamodb-as-cache.png)](https://www.npmjs.com/package/dynamodb-as-cache)\n\n# DynamoDB as Cache\n\nUse DynamoDB as cache service, providing Redis-like APIs and reducing the boilerplate of dealing low-level DynamoDB APIs. \n\n## Why\n\nDynamoDB requires minimum maintenance overhead and has acceptable performance in caching data. Often we just need a simple centralized key-value storage for our distributed services. \n\nWhere extreme performance is required, we can still easily migrate our code to use Redis. \n\n\n## Installation\n\n```shell\nnpm i dynamodb-as-cache\n```\n\n## Example\n\n```js\nconst { DCacheClient } = require('../index')\nconst { promisify } = require('util')\n\nconst sleep = promisify(setTimeout)\n\nasync function main() {\n  try {\n    const client = new DCacheClient({\n      region: process.env.AWS_REGION,\n      tableName: process.env.TABLE_NAME\n    })\n\n    await client.set('foo', { message: 'hello foo' }, 1)\n    await client.set('bar', { message: 'hello bar' }, 10)\n    await sleep(3000)\n    const v1 = await client.get('foo')\n    const v2 = await client.get('bar')\n\n    v1? console.log('v1: cache hit =\u003e', v1) : console.log('v1: cache miss')\n    v2? console.log('v2: cache hit =\u003e', v2) : console.log('v2: cache miss')\n\n    const _v3 = await client.getset('foo', { message: 'hello foo again' }, 1)\n    const _v4 = await client.getset('bar', { message: 'hello bar again' }, 10)\n    const v3 = await client.get('foo')\n    const v4 = await client.get('bar')\n    console.log(`v3: old = ${_v3}  new= ${v3}`)    \n    console.log(`v4: old = ${_v4}  new= ${v4}`)    \n\n  } catch (e) {\n    console.error('something went wrong', e)\n  }\n}\n\nmain().catch(console.error)\n\n```\n\n## API\n\n### constructor(options)\n\n#### Options\n* `region` - _string_, required. AWS region, e.g. us-east-1\n* `tableName` - _string_, required. DynamoDB table name\n* `accessKeyId` - _string_, optional. AWS Access Key Id\n* `secretAccessKey` - _string_, optional. AWS Secret Access Key\n* `partionKey` - _string_, optional. (default: `pkey`)\n* `sortKey` - _string_, optional. (default: `skey`)\n* `ttlAttribute` - _string_, optional. (default: `ttl`)\n* `consistentRead` - _boolean_, optional. (default: `false`)\n* `defaultSortKeyValue` - _string_, optional. (default: `DCache`)\n\n### set(pkey, value, ttl = null, options)\n\nReturns Promise, which \n* __resovled__ with empty object\n* __rejected__ when dynamodb throws error\n\nArguments: \n* `pkey` partition key\n* `value` value to cache\n* `ttl` time to live (in seconds), `default: null`\n* `options` options, `default: {}`\n\n### getset(pkey, value, ttl = null, options)\n\nReturns Promise, which \n* __resovled__ with old cached value\n* __rejected__ when dynamodb throws error\n\nArguments: \n* `pkey` partition key\n* `value` value to cache\n* `ttl` time to live (in seconds), `default: null`\n* `options` options, `default: {}`\n\n### get(pkey, options)\n\nReturns Promise, which \n* __resovled__ with cached value\n* __rejected__ when dynamodb throws error\n\nArguments: \n* `pkey` partition key\n* `options` options, `default: {}`\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsimple-dev-tools%2Fdynamodb-as-cache","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsimple-dev-tools%2Fdynamodb-as-cache","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsimple-dev-tools%2Fdynamodb-as-cache/lists"}