Add clear method to MapCache.

This commit is contained in:
Aaron Hamid
2015-12-17 18:54:51 -05:00
committed by John-David Dalton
parent 71fb66dc37
commit 380435d020
2 changed files with 34 additions and 0 deletions

View File

@@ -1939,6 +1939,17 @@
return this;
}
/**
* Clears the map data
*
* @private
* @name clear
* @memberOf MapCache
*/
function mapClear() {
this.__data__ = { 'hash': new Hash, 'map': Map ? new Map : [], 'string': new Hash };
}
/*------------------------------------------------------------------------*/
/**
@@ -13737,6 +13748,7 @@
Hash.prototype = nativeCreate ? nativeCreate(null) : objectProto;
// Add functions to the `MapCache`.
MapCache.prototype.clear = mapClear;
MapCache.prototype['delete'] = mapDelete;
MapCache.prototype.get = mapGet;
MapCache.prototype.has = mapHas;

View File

@@ -12485,6 +12485,28 @@
_.memoize.Cache = oldCache;
});
QUnit.test('should allow clearing cache', function(assert) {
assert.expect(5);
var memoized = _.memoize(_.identity);
assert.strictEqual(memoized.cache.has('a'), false);
memoized('a');
assert.strictEqual(memoized.cache.has('a'), true);
memoized.cache.clear();
assert.strictEqual(memoized.cache.has('a'), false);
memoized('a');
memoized('b');
assert.strictEqual(memoized.cache.has('a'), true);
assert.strictEqual(memoized.cache.has('b'), true);
});
}());
/*--------------------------------------------------------------------------*/