interface Options { path?: string; // defaults to './store.json ttl?: number; // defaults to 900000ms (15 minutes) resetOnFailure?: boolean; // whether to reset the store if it couldn't be repaired}
How it works?
When the store file (./store.json by default) does not exist, it will be created automatically.
If the file can't be read (possibly due to invalid format), the module will attempt to repair it (to avoid data loss).
If the repairing process can't finish, the module will delete it and create a new one (possibly resulting in data loss).
If the file is valid and contains the information about TTL and creation time, the module will check whether the TTL hasn't yet expired.
The module will now be able to read/write data. Writing is done atomically, so that unexpected shutdowns won't corrupt the store file.