diff --git a/src/ng/cacheFactory.js b/src/ng/cacheFactory.js index 850d48f297e2..51e0d441a240 100644 --- a/src/ng/cacheFactory.js +++ b/src/ng/cacheFactory.js @@ -14,7 +14,7 @@ * @returns {object} Newly created cache object with the following set of methods: * * - `{object}` `info()` — Returns id, size, and options of cache. - * - `{void}` `put({string} key, {*} value)` — Puts a new key-value pair into the cache. + * - `{{*}}` `put({string} key, {*} value)` — Puts a new key-value pair into the cache. * - `{{*}}` `get({string} key)` — Returns cached value for `key` or undefined for cache miss. * - `{void}` `remove({string} key)` — Removes a key-value pair from the cache. * - `{void}` `removeAll()` — Removes all cached values. @@ -46,13 +46,15 @@ function $CacheFactoryProvider() { refresh(lruEntry); - if (isUndefined(value)) return; + if (isUndefined(value)) return value; if (!(key in data)) size++; data[key] = value; if (size > capacity) { this.remove(staleEnd.key); } + + return value; }, diff --git a/test/ng/cacheFactorySpec.js b/test/ng/cacheFactorySpec.js index dc68b63d45fa..a2a2ef991c23 100644 --- a/test/ng/cacheFactorySpec.js +++ b/test/ng/cacheFactorySpec.js @@ -99,6 +99,12 @@ describe('$cacheFactory', function() { cache.remove(123); expect(cache.info().size).toBe(0); })); + + it("should return value from put", inject(function($cacheFactory) { + function DummyClass() {} + var obj = new DummyClass(); + expect(cache.put('k1', obj)).toBe(obj); + })); });