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

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 #1497
  • Loading branch information
jtymes authored and IgorMinar committed Nov 24, 2012
1 parent c0de8fb commit 1eb9e22
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 1eb9e22

Please sign in to comment.