a zip code crypto-currency system good for red ONLY

_memoizeCapped.js 633B

123456789101112131415161718192021222324252627
  1. var memoize = require('./memoize');
  2. /** Used as the maximum memoize cache size. */
  3. var MAX_MEMOIZE_SIZE = 500;
  4. /**
  5. * A specialized version of `_.memoize` which clears the memoized function's
  6. * cache when it exceeds `MAX_MEMOIZE_SIZE`.
  7. *
  8. * @private
  9. * @param {Function} func The function to have its output memoized.
  10. * @returns {Function} Returns the new memoized function.
  11. */
  12. function memoizeCapped(func) {
  13. var result = memoize(func, function(key) {
  14. if (cache.size === MAX_MEMOIZE_SIZE) {
  15. cache.clear();
  16. }
  17. return key;
  18. });
  19. var cache = result.cache;
  20. return result;
  21. }
  22. module.exports = memoizeCapped;