From 55d15806fb14b1d98b5ca2770bbbb59e11548c62 Mon Sep 17 00:00:00 2001 From: Jeremy Tymes Date: Tue, 13 Nov 2012 07:33:26 -0500 Subject: [PATCH] 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 --- src/ng/cacheFactory.js | 2 ++ test/ng/cacheFactorySpec.js | 5 +++++ 2 files changed, 7 insertions(+) diff --git a/src/ng/cacheFactory.js b/src/ng/cacheFactory.js index 850d48f297e2..2ff02a374c60 100644 --- a/src/ng/cacheFactory.js +++ b/src/ng/cacheFactory.js @@ -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); diff --git a/test/ng/cacheFactorySpec.js b/test/ng/cacheFactorySpec.js index dc68b63d45fa..88e8e523c627 100644 --- a/test/ng/cacheFactorySpec.js +++ b/test/ng/cacheFactorySpec.js @@ -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');