Skip to content

Commit

Permalink
fix($cacheFactory): return undefined when removing non-existent entry
Browse files Browse the repository at this point in the history
Instead of throwning an exception, remove should return undefined when
cache entry to be removed doesn't exist.

Closes angular#1497
  • Loading branch information
jtymes authored and IgorMinar committed Nov 26, 2012
1 parent d2d9762 commit 2019226
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/ng/cacheFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
5 changes: 5 additions & 0 deletions test/ng/cacheFactorySpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down

0 comments on commit 2019226

Please sign in to comment.