From 168db33985aa025eb48bc21087717ab70da0bd72 Mon Sep 17 00:00:00 2001 From: JP Sugarbroad Date: Thu, 15 Nov 2012 15:18:28 -0800 Subject: feat($cacheFactory): cache.put now returns the added value This allows common programming patterns to be expressed with more concise code. See #1583 for code examples. --- src/ng/cacheFactory.js | 4 +++- test/ng/cacheFactorySpec.js | 6 ++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/ng/cacheFactory.js b/src/ng/cacheFactory.js index 2ff02a37..ce690ebf 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 and returns it. * - `{{*}}` `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. @@ -53,6 +53,8 @@ function $CacheFactoryProvider() { if (size > capacity) { this.remove(staleEnd.key); } + + return value; }, diff --git a/test/ng/cacheFactorySpec.js b/test/ng/cacheFactorySpec.js index 88e8e523..ddfadbbc 100644 --- a/test/ng/cacheFactorySpec.js +++ b/test/ng/cacheFactorySpec.js @@ -104,6 +104,12 @@ describe('$cacheFactory', function() { cache.remove(123); expect(cache.info().size).toBe(0); })); + + + it("should return value from put", inject(function($cacheFactory) { + var obj = {}; + expect(cache.put('k1', obj)).toBe(obj); + })); }); -- cgit v1.2.3