cacheable-methods-dynamodb
TypeScript icon, indicating that this package has built-in type declarations

1.0.5 • Public • Published

The decorator @Cacheable(ttl, [tablename])

The Decorator for caching class methods data.

Install:

npm install cacheable-methods-dynamodb

Documentation:

@Cacheable is a decorator that caches your methods result in dynamoDb. It as 2 arguments :

  • ttl ( the time to leave in Days)
  • (optional) tablename ( the name of the dynamoDb table you wants to use, default is cache)


IN ORDER TO GET THIS WORKING YOUR TABLE HAVE TO HAVE A SINGLE PRIMARY KEY (key-schema) named : cacheKey
Cli declation exemple: --key-schema AttributeName=cacheKey,KeyType=HASH

Usage exemple:

@Cacheable(1) // Cache 1 day on default table cache
@Cacheable(7, 'customCacheTable') //Cache 7 day on customCacheTable table

Exemple of implementation:

import Cacheable from 'cacheable-methods-dynamodb';

class TestClass {
  //one Day
  @Cacheable(1)
  public async getUserById(id: string, param: any): Promise<any> {
    return {
        name: "olivier",
        prenom: "andrae"
    };
  }

}
(async ()=>{
    const a = new TestClass();
    console.log(await a.getUserById("12", {o: 2}));
})();

.env variables:

LOCAL=true // will connect to http://localhost:8000
DEBUG=false

AWS Credentials

They are taken from yout local setup, usualy ~/.aws folder

Package Sidebar

Install

npm i cacheable-methods-dynamodb

Weekly Downloads

9

Version

1.0.5

License

MIT

Unpacked Size

47.4 kB

Total Files

46

Last publish

Collaborators

  • andrade0