You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
`@mish-tv/cache` is a simple cache library that holds a single value in a single instance.
Installation
npm install --save @mish-tv/cache
Simple Usage
import{Cache}from"@mish-tv/cache";// By default, it caches for 1hour + rand()*6min.constentityCache=newCache<Entity>();// Only at the beginning and when it expires,// it calls an anonymous function passed as an argument and// caches the returned value.constgetEntity=()=>entityCache.get(async()=>{constentity: Entity=awaitfetch();returnentity;});(async()=>{constentity=awaitgetEntity();})();
Other Usage
// You can configure ttl, jitter and initial value.constentityCache=newCache(60000,1000,entity);// You can create a cache that will never expire.constentityCache=newCache("infinity");