Skip to content

Commit c5f1304

Browse files
taralxIgorMinar
authored andcommitted
feat($cacheFactory): cache.put now returns the added value
This allows common programming patterns to be expressed with more concise code. See angular#1583 for code examples.
1 parent c72d2d6 commit c5f1304

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

src/ng/cacheFactory.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* @returns {object} Newly created cache object with the following set of methods:
1515
*
1616
* - `{object}` `info()` — Returns id, size, and options of cache.
17-
* - `{void}` `put({string} key, {*} value)` — Puts a new key-value pair into the cache.
17+
* - `{{*}}` `put({string} key, {*} value)` — Puts a new key-value pair into the cache and returns it.
1818
* - `{{*}}` `get({string} key)` — Returns cached value for `key` or undefined for cache miss.
1919
* - `{void}` `remove({string} key)` — Removes a key-value pair from the cache.
2020
* - `{void}` `removeAll()` — Removes all cached values.
@@ -53,6 +53,8 @@ function $CacheFactoryProvider() {
5353
if (size > capacity) {
5454
this.remove(staleEnd.key);
5555
}
56+
57+
return value;
5658
},
5759

5860

test/ng/cacheFactorySpec.js

+6
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,12 @@ describe('$cacheFactory', function() {
104104
cache.remove(123);
105105
expect(cache.info().size).toBe(0);
106106
}));
107+
108+
109+
it("should return value from put", inject(function($cacheFactory) {
110+
var obj = {};
111+
expect(cache.put('k1', obj)).toBe(obj);
112+
}));
107113
});
108114

109115

0 commit comments

Comments
 (0)