You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
constKeyv=require('keyv')const{ KeyvFile }=require('keyv-file')constkeyv=newKeyv({store: newKeyvFile()});// More options with default value:constcustomKeyv=newKeyv({store: newKeyvFile({filename: `${os.tmpdir()}/keyv-file/default-rnd-${Math.random().toString(36).slice(2)}.json`,// the file path to store the dataexpiredCheckDelay: 24*3600*1000,// ms, check and remove expired data in each mswriteDelay: 100,// ms, batch write to disk in a specific duration, enhance write performance.encode: JSON.stringify,// serialize functiondecode: JSON.parse// deserialize function})})
Using directly
importKeyvFile,{makeField}from'keyv-file'classKvextendsKeyvFile{constructor(){super({filename: './db.json'})}someField=makeField(this,'field_key')}exportconstkv=newKvkv.someField.get(1)// empty return default value 1kv.someField.set(2)// set value 2kv.someField.get()// return saved value 2kv.someField.delete()// delete field
License
MIT
About
File storage adapter for Keyv, using json to serialize data.