SLSC
Small Local Storage Cache
small library to store cache data in localstorage with auto remove (ttl)
using example
import the SLSCache library
import SLSCache from 'sls-cache'
config default values of the TTL and the cache tag name
SLSCache.config({ cacheName: 'slscache', defaultTTL: 10 });
Config | Type | Default |
---|---|---|
cacheName | string | slscache |
TTL | number | 60 minutes |
SLSCache.set('use unique key', 'data of any type', 6);
SLSCache.set('use unique key', 'data of any type without specific TTL');
SLSCache.get('unique key');
supporting typescript
interface Interface {
val: string;
}
const obj: Interface = { val: 'my value' };
SLSCache.set('obj', obj);
const data = SLSCache.get<Interface>('obj');
console.log(data?.val);
Methods | args |
---|---|
set | (key, data, ttl) |
get | key |