Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit 55d1580

Browse files
jtymesIgorMinar
authored andcommitted
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
1 parent 94e1c03 commit 55d1580

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

src/ng/cacheFactory.js

+2
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ function $CacheFactoryProvider() {
7070
remove: function(key) {
7171
var lruEntry = lruHash[key];
7272

73+
if (!lruEntry) return;
74+
7375
if (lruEntry == freshEnd) freshEnd = lruEntry.p;
7476
if (lruEntry == staleEnd) staleEnd = lruEntry.n;
7577
link(lruEntry.n,lruEntry.p);

test/ng/cacheFactorySpec.js

+5
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,11 @@ describe('$cacheFactory', function() {
8989
}));
9090

9191

92+
it('should return undefined when entry does not exist', inject(function($cacheFactory) {
93+
expect(cache.remove('non-existent')).toBeUndefined();
94+
}));
95+
96+
9297
it('should stringify keys', inject(function($cacheFactory) {
9398
cache.put('123', 'foo');
9499
cache.put(123, 'bar');

0 commit comments

Comments
 (0)