Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit a2f938a

Browse files
committedNov 16, 2012
feat($cacheFactory): Make Cache.put return the value.
1 parent bd524fc commit a2f938a

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed
 

‎src/ng/cacheFactory.js

Lines changed: 4 additions & 2 deletions
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.
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.
@@ -46,13 +46,15 @@ function $CacheFactoryProvider() {
4646

4747
refresh(lruEntry);
4848

49-
if (isUndefined(value)) return;
49+
if (isUndefined(value)) return value;
5050
if (!(key in data)) size++;
5151
data[key] = value;
5252

5353
if (size > capacity) {
5454
this.remove(staleEnd.key);
5555
}
56+
57+
return value;
5658
},
5759

5860

‎test/ng/cacheFactorySpec.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,12 @@ describe('$cacheFactory', function() {
9999
cache.remove(123);
100100
expect(cache.info().size).toBe(0);
101101
}));
102+
103+
it("should return value from put", inject(function($cacheFactory) {
104+
function DummyClass() {}
105+
var obj = new DummyClass();
106+
expect(cache.put('k1', obj)).toBe(obj);
107+
}));
102108
});
103109

104110

0 commit comments

Comments
 (0)
This repository has been archived.