https://github.com/52cik/storecache
Storage with expiration time based on localStorage
https://github.com/52cik/storecache
Last synced: 2 months ago
JSON representation
Storage with expiration time based on localStorage
- Host: GitHub
- URL: https://github.com/52cik/storecache
- Owner: 52cik
- License: mit
- Created: 2018-01-17T05:56:41.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2018-01-18T03:42:26.000Z (over 7 years ago)
- Last Synced: 2025-02-28T05:52:51.559Z (3 months ago)
- Language: TypeScript
- Size: 13.7 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# storecache
> Storage with expiration time based on localStorage
## Requirements
> node6 or higher
## How to use it
### Install
```sh
$ yarn add storecache.js
# or
$ npm i -S storecache.js
```### Usage
```js
const StoreCache = require('storecache.js');const store = new StoreCache();
store.set('obj', { a: 1, b: { c: 'str' } });
console.log(store.get('obj')); // { a: 1, b: { c: 'str' } }store.set('expired', { id: 123 }, 3); // expire after 3 seconds
console.log(store.get('expired')); // { id: 123 }
setTimeout(() => {
console.log(store.get('expired')); // null
}, 4000);
```## API
#### StoreCache([options])
##### options
Type: `Object`
###### prefix
Type: `string`
Default: ''
###### store
Type: `Storage`
Default: localStorage
#### StoreCache#set(sid, data, ttl)
###### sid
Type: `string`
###### data
Type: `any`
###### ttl
Type: `number`
Default: 0
#### StoreCache#get(sid)
###### sid
Type: `string`
#### StoreCache#touch(sid, ttl)
###### sid
Type: `string`
###### ttl
Type: `number`
Default: 0
#### StoreCache#destroy(sid)
###### sid
Type: `string`
#### StoreCache#clear()