keyv-file ![keyv](https://rawgit.com/lukechilds/keyv/master/media/logo.svg)
File storage adapter for Keyv, using json to serialize data fast and small.
![npm](https://img.shields.io/npm/v/keyv-file.svg)
File storage adapter for Keyv.
TTL functionality is handled internally by interval scan, don't need to panic about expired data take too much space.
Install
npm install --save keyv keyv-file
Usage
Using with keyv
const Keyv = require('keyv')
const { KeyvFile } = require('keyv-file')
const keyv = new Keyv({
store: new KeyvFile()
});
const customKeyv = new Keyv({
store: new KeyvFile({
filename: `${os.tmpdir()}/keyv-file/default-rnd-${Math.random().toString(36).slice(2)}.json`,
expiredCheckDelay: 24 * 3600 * 1000,
writeDelay: 100,
encode: JSON.stringify,
decode: JSON.parse
})
})
Using directly
import KeyvFile, { makeField } from 'keyv-file'
class Kv extends KeyvFile {
constructor() {
super({
filename: './db.json'
})
}
someField = makeField(this, 'field_key')
}
export const kv = new Kv
kv.someField.get(1)
kv.someField.set(2)
kv.someField.get()
kv.someField.delete()
License
MIT