mirror of
https://github.com/Hopiu/angular.js.git
synced 2026-03-17 07:40:22 +00:00
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:
parent
94e1c0391c
commit
55d15806fb
2 changed files with 7 additions and 0 deletions
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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');
|
||||
|
|
|
|||
Loading…
Reference in a new issue