fix($cacheFactory): return undefined when removing non-existent entry

Instead of throwning an exception, remove should return undefined when
cache entry to be removed doesn't exist.

Closes #1497
This commit is contained in:
Jeremy Tymes 2012-11-13 07:33:26 -05:00 committed by Igor Minar
parent 94e1c0391c
commit 55d15806fb
2 changed files with 7 additions and 0 deletions

View file

@ -70,6 +70,8 @@ function $CacheFactoryProvider() {
remove: function(key) {
var lruEntry = lruHash[key];
if (!lruEntry) return;
if (lruEntry == freshEnd) freshEnd = lruEntry.p;
if (lruEntry == staleEnd) staleEnd = lruEntry.n;
link(lruEntry.n,lruEntry.p);

View file

@ -89,6 +89,11 @@ describe('$cacheFactory', function() {
}));
it('should return undefined when entry does not exist', inject(function($cacheFactory) {
expect(cache.remove('non-existent')).toBeUndefined();
}));
it('should stringify keys', inject(function($cacheFactory) {
cache.put('123', 'foo');
cache.put(123, 'bar');