Skip to content
This repository has been archived by the owner on Apr 12, 2024. It is now read-only.

Commit

Permalink
feat($cacheFactory): cache.put now returns the added value
Browse files Browse the repository at this point in the history
This allows common programming patterns to be expressed with more
concise code.

See #1583 for code examples.
  • Loading branch information
taralx authored and IgorMinar committed Nov 24, 2012
1 parent 79af2ba commit 168db33
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/ng/cacheFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -53,6 +53,8 @@ function $CacheFactoryProvider() {
if (size > capacity) {
this.remove(staleEnd.key);
}

return value;
},


Expand Down
6 changes: 6 additions & 0 deletions test/ng/cacheFactorySpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}));
});


Expand Down

0 comments on commit 168db33

Please sign in to comment.