Use localStorage to implement expired cache.
Use the two strategies of lazy deletion and scheduled deletion to clean up the expired cache.
Include the JavaScript script in your HTML markup:
<script src="js/lsc.js"></script>
In your application code, set the cache to localStorage by calling the lsc.set method with the key, value, and expiration time as parameters:
lsc.set('DemoKey', 'DemoValue', 5);
Get the cached value from localStorage by calling the lsc.get method with the key as the parameter:
var val = lsc.get('DemoKey');
The LocalStorageCache script has zero dependencies.
The LocalStorageCache is released under the MIT license.