Asynchronous local storage (Write through cache)
A local storage wrapper, that helps to write data to disk asynchronously. It uses in-mem cache for faster "READ"
Install
npm install as-store
Usage
Methods:
-
AsStore.setItem(key, value)
- setvalue
forkey
inas-store
-
AsStore.getItem(key)
- lookup data forkey
fromas-store
-
AsStore.removeItem(key)
- removekey
fromas-store
-
AsStore.flush()
- flush all the data fromas-store
-
AsStore.onWriteComplete(function)
- attach handler to disk "WRITE".funciton
will be called when writing to disk.
Why it's fast and non-blocking ?
setItem
- doesn't write the data to disk immediately. Non-blocking. Process multiple write operation at once (with 500ms throttling).
getItem
- doesn't read data from disk. It maintain a hash map in client. It directly returns data from memory.