single-access-cache

1.0.0 • Public • Published

single-access-cache

Cache that ensures single access to the cache. Usefull when dealing with oAuth tokens and similar things.

API

const SingleAccessCache = require('single-access-cache');


const myCache = new SingleAccessCache({
  acquire:async function(){
     //Get item to cache in some way
     return {
         item:"Cacheworthy",//Anything
         expires:(new Date()).getTime() + 60*60*10000 //Expiry time in ms since epoch
     }
  }
});
let item = await myCache.getItem();
console.log(item);
// prints Cacheworthy
//If the item expires before the expire time, you can clear it using clearItem

await myCache.clearItem()

Readme

Keywords

none

Package Sidebar

Install

npm i single-access-cache

Weekly Downloads

1

Version

1.0.0

License

MIT

Unpacked Size

14.1 kB

Total Files

7

Last publish

Collaborators

  • mvollset