1.0.1 • Published 2 months ago

ttl-flat-cache-fixed v1.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
2 months ago

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
1.0.1

2 months ago

1.0.0

2 months ago