ttl-flat-cache-fixed
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

Why?

flat-cache is amazing and I wanted to extend it to add a TLL (key expiry) feature.

Using

    //Some cache options
    const cacheOpts = {
      // namespace to use
      ns: "shorticle-cache",
      // time to live
      ttl: 3600 * 24,
      //dir: '/Directory-To-Save-Data'
    };
    
    const cache = require(".")(cacheOpts);
    
    let key = "test-key",
      value = {tyope:"Object", name:"Some Fancy Object to cache"};
    
    cache.set(key, value, 30);
    
    console.log(cache.ttl(key));
    console.log(cache.get(key));

This will print:

    { key: 'test-key', expires: 'in a few seconds' }
    { tyope: 'Object', name: 'Some Fancy Object to cache' }

NOTE:

  • ttl defaults to null, meaning no expiry.
  • you can use .get(), .set() and .del() methods which map to flat-caches .getKey(), .setKey() and .removeKey() respectively.
  • all option values are optional

/ttl-flat-cache-fixed/

    Package Sidebar

    Install

    npm i ttl-flat-cache-fixed

    Weekly Downloads

    364

    Version

    1.0.1

    License

    MIT

    Unpacked Size

    18.3 kB

    Total Files

    5

    Last publish

    Collaborators

    • gkiselev