You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

_memoizeCapped.js 633B

1234567891011121314151617181920212223242526
  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;