# holdon **Repository Path**: mirrors_WebReflection/holdon ## Basic Information - **Project Name**: holdon - **Description**: A simple unique key based cache - **Primary Language**: Unknown - **License**: MIT - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2020-08-19 - **Last Updated**: 2025-12-27 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README holdon ====== [![build status](https://secure.travis-ci.org/WebReflection/holdon.png)](http://travis-ci.org/WebReflection/holdon) # A simple, non atomic, unique key/values based cache Specially handy in all those situations where one unique id can perform an asynchronous action you don't want to drop the first time is called but you want to store all listeners waiting for such result. Here’s a good explanation: . ### Simplified API for common cases ```js module.exports = function (path, callback) { // true only if created first time if (cache.add(path, callback)) { fs.readFile(path, function (err, res) { // remove returns the object too cache.remove(path).callback.forEach( onFileRead, {err: err, res: res} ); }); } }; function onFileRead(callback) { callback.call(null, this.err, this.res); } ``` ### Full API example ```js // module: filereader var fs = require('fs'); // a generic module cache // with a callback property var cache = require('holdon').create(['callback']); function onFileRead(callback) { callback.call(null, this.err, this.res); } module.exports = function (path, callback) { if (!cache.has(path)) { fs.readFile(path, function (err, res) { var result = cache.get(path); // clean this id cache.remove(path); // invoke all waiting callbacks result.callback.forEach(onFileRead, {err: err, res: res}); }); } // add the path to the queue cache.add(path, callback); }; ``` In another file ... ```js var filereader = require('filereader'); // whenever is needed filereader('anyFile.md', function (err, res) { // do something ... }); filereader('anyFile.md', function (err, res) { // do something ... }); filereader('anyFile.md', function (err, res) { // do something ... }); // it does not matter how many asking, the disk will read it once ```