Little cache lib using localStorage and promises.
You just have to include cache.js :
<script type="text/javascript" src="https://drulac.github.io/cache.js/cache.js"></script>
Create a cache object :
let cache = new Cache();
Add a custom method using cache.newMethod(methodName, promise, validTimeInSecond)
:
cache.newMethod("methodName", (arg1, arg2)=>{
return new Promise((resolve, reject)=>{
//work
let result = arg1 + arg2;
resolve(result);
});
}, 10); //valid time in seconds
then you can call your custom method like a normal method :
cache.methodName();
That will return a promise. The data is automaticaly updated when she have expirate.