https://github.com/workable/idb
https://github.com/workable/idb
Last synced: 8 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/workable/idb
- Owner: Workable
- License: mit
- Created: 2020-02-13T10:47:14.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2024-04-12T15:17:13.000Z (almost 2 years ago)
- Last Synced: 2025-03-13T19:45:46.069Z (about 1 year ago)
- Language: JavaScript
- Size: 1.72 MB
- Stars: 0
- Watchers: 13
- Forks: 1
- Open Issues: 17
-
Metadata Files:
- Readme: readme.md
- License: LICENSE
Awesome Lists containing this project
README
# idb
A simple cache mechanisms that is based on IndexDB.
## Installing
Using npm:
```
$ npm install @workablehr/idb
```
## Basic usage
```javascript
import makeIDB from "@workablehr/idb";
const idb = makeIDB("workable-store");
idb.get("myKey", { fetch: performFetch, maxAge: 100 });
// if 'myKey' does not exists, it fetches and stores the result for 100 seconds
```
## API
```javascript
import makeIDB from "@workablehr/idb";
const { store, set, get, clear, del } = makeIDB("workable-store");
```
All the actions are namespaced by the store name.
### set (key, value)
Sets the an entry in the indexed db
### get (key, {fetch, maxAge})
Gets a value from the indexed db.
If the value does not exists, it calls the `fetch` function and stores the
result for `maxAge` period.
### clear
Clears all the entries that are owned by the `workable-store`
### del (key)
Deletes a specific entry in the index db.