Two-level memoizer
with promises stores function values in memory and/or file caches.
Writes to memory and file caches can be independently
changed on demand.
The file cache is stored in the application local
folder
by default, so you may want to add local/
to .gitignore
.
For more examples, see test/memoizer.js
const { Memoizer } = require("memo-again");
var f = x=>42+x;
var mzr = new Memoizer();
var fmemo = mzr.memoize(f);
fmemo(0); // 42
fmemo(0); // 42 (cached)
fmemo(1); // 43
fmemo(1); // 43 (cached)
File iterators and more...
Async generator permits precise control of thread usage.
var files = [];
for await (let f of Files.files(FILES_DIR)) {
files.unshift(f);
}
// [ "hello", "sub/basement", "universe", ]
Async generator provides fs.Stats
var opts = {
root: FILES_DIR,
stats: true, // return fs.Stats object
absolute: true, // return absolute filepath
}
for await (let f of Files.files(FILES_DIR)) {
console.log(JSON.stringify(f));
// {path:..., stats:...}
}
Sync generator uses fs sync methods and can be slower.
var files = [...Files.filesSync(FILES_DIR)];
// [ "hello", "sub/basement", "universe", ]
The application that uses this library
console.log(Files.APP_DIR);
// /home/somebody/myapp
Use "local" folder for application data.
Remember to add it to .gitignore
console.log(Files.LOCAL_DIR);
// /home/somebody/myapp/local