@newdash/newdash
Version:
javascript/typescript utility library
28 lines (27 loc) • 910 B
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const memoize_1 = __importDefault(require("../memoize"));
/** Used as the maximum memoize cache size. */
const MAX_MEMOIZE_SIZE = 500;
/**
* A specialized version of `memoize` which clears the memoized function's
* cache when it exceeds `MAX_MEMOIZE_SIZE`.
*
* @private
* @param {Function} func The function to have its output memoized.
* @returns {Function} Returns the new memoized function.
*/
function memoizeCapped(func) {
const result = (0, memoize_1.default)(func, (key) => {
const { cache } = result;
if (cache.size === MAX_MEMOIZE_SIZE) {
cache.clear();
}
return key;
});
return result;
}
exports.default = memoizeCapped;