Simple memory cache function.
Some times you want to cache a value but don't need a complex caching system. This package helps you cache values in side the memory of your application.
yarn add @kaliber/cache
importfetchfrom'node-fetch'import{createCache}from'@kaliber/cache'constcache=createCache({allowReturnExpiredValue: false,expirationTime: 1000})functionhandleRequest(postId){constdata=cache({cacheKey: ['post',postId],asyncgetValue(){constresponse=awaitfetch(`https://jsonplaceholder.typicode.com/posts/${postId}`)returnawaitresponse.json()}})returndata}| Property | Value | Description |
|---|---|---|
| allowReturnExpiredValue | false | if false the expirationTime will be leading in getting results from the cache |
| allowReturnExpiredValue | true | if true the cache is in 'unsafe' safe mode this means that the cache will always return a value even if the cache time is expired. Of course the cache needs to have a value to get value from it. |
| expirationTime | number | (in milliseconds) this is the time the cache is valid. |
This library is intended for internal use, we provide no support, use at your own risk.