Nuclear Package Magnet

    @express.ts/cache
    TypeScript icon, indicating that this package has built-in type declarations

    1.0.1 • Public • Published

    @express.ts/cache

    A simple in-memory cache for @express.ts

    Installation

    npm install @express.ts/cache --save
    

    Usage

    Test.ts

    import { Cache } from "@express.ts/cache";
    
    export class Test {
    
      protected value = Date.now();
    
      getExecutionTime () {
        return Date.now() - this.value;
      }
    
      @Cache(1000) // 1s
      getExecutionTimeWithCache () {
        return Date.now() - this.value;
      }
    
    }

    App.ts

    import { Test } from "./Test";
    
    const testInstance = new Test();
    
    console.log([ // [ 4, 4 ]
      testInstance.getExecutionTime(),
      testInstance.getExecutionTimeWithCache()
    ]);
    
    console.log([ // [ 24, 4 ]
      testInstance.getExecutionTime(),
      testInstance.getExecutionTimeWithCache()
    ]);
    
    setTimeout(() => {
      console.log([ // [ 1038, 1038 ]
        testInstance.getExecutionTime(),
        testInstance.getExecutionTimeWithCache()
      ]);
    }, 1001)

    Keywords

    none

    Install

    npm i @express.ts/cache

    DownloadsWeekly Downloads

    1

    Version

    1.0.1

    License

    MIT

    Unpacked Size

    133 kB

    Total Files

    16

    Last publish

    Collaborators

    • aboulmane