sls-cache

1.0.2 • Public • Published

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



Source Code In GitHub

Package Sidebar

Install

npm i sls-cache

Weekly Downloads

19

Version

1.0.2

License

MIT

Unpacked Size

30.8 kB

Total Files

13

Last publish

Collaborators

  • karamj