Last change
on this file since eed0bf8 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago |
initial commit
|
-
Property mode
set to
100644
|
File size:
633 bytes
|
Rev | Line | |
---|
[6a3a178] | 1 | var memoize = require('./memoize');
|
---|
| 2 |
|
---|
| 3 | /** Used as the maximum memoize cache size. */
|
---|
| 4 | var MAX_MEMOIZE_SIZE = 500;
|
---|
| 5 |
|
---|
| 6 | /**
|
---|
| 7 | * A specialized version of `_.memoize` which clears the memoized function's
|
---|
| 8 | * cache when it exceeds `MAX_MEMOIZE_SIZE`.
|
---|
| 9 | *
|
---|
| 10 | * @private
|
---|
| 11 | * @param {Function} func The function to have its output memoized.
|
---|
| 12 | * @returns {Function} Returns the new memoized function.
|
---|
| 13 | */
|
---|
| 14 | function memoizeCapped(func) {
|
---|
| 15 | var result = memoize(func, function(key) {
|
---|
| 16 | if (cache.size === MAX_MEMOIZE_SIZE) {
|
---|
| 17 | cache.clear();
|
---|
| 18 | }
|
---|
| 19 | return key;
|
---|
| 20 | });
|
---|
| 21 |
|
---|
| 22 | var cache = result.cache;
|
---|
| 23 | return result;
|
---|
| 24 | }
|
---|
| 25 |
|
---|
| 26 | module.exports = memoizeCapped;
|
---|
Note:
See
TracBrowser
for help on using the repository browser.