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

Commit 3cad63f

Browse files
itamarropetebacondarwin
authored andcommitted
docs($cacheFactory): show that you can access existing caches
1 parent d2be593 commit 3cad63f

File tree

1 file changed

+35
-1
lines changed

1 file changed

+35
-1
lines changed

src/ng/cacheFactory.js

+35-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,20 @@
33
* @name ng.$cacheFactory
44
*
55
* @description
6-
* Factory that constructs cache objects.
6+
* Factory that constructs cache objects and gives access to them.
7+
*
8+
* <pre>
9+
*
10+
* var cache = $cacheFactory('cacheId');
11+
* expect($cacheFactory.get('cacheId')).toBe(cache);
12+
* expect($cacheFactory.get('noSuchCacheId')).not.toBeDefined();
13+
*
14+
* cache.put("key", "value");
15+
* cache.put("another key", "another value");
16+
*
17+
* expect(cache.info()).toEqual({id: 'cacheId', size: 2}); // Since we've specified no options on creation
18+
*
19+
* </pre>
720
*
821
*
922
* @param {string} cacheId Name or id of the newly created cache.
@@ -135,6 +148,16 @@ function $CacheFactoryProvider() {
135148
}
136149

137150

151+
/**
152+
* @ngdoc method
153+
* @name ng.$cacheFactory#info
154+
* @methodOf ng.$cacheFactory
155+
*
156+
* @description
157+
* Get information about all the of the caches that have been created
158+
*
159+
* @returns {Object} - key-value map of `cacheId` to the result of calling `cache#info`
160+
*/
138161
cacheFactory.info = function() {
139162
var info = {};
140163
forEach(caches, function(cache, cacheId) {
@@ -144,6 +167,17 @@ function $CacheFactoryProvider() {
144167
};
145168

146169

170+
/**
171+
* @ngdoc method
172+
* @name ng.$cacheFactory#get
173+
* @methodOf ng.$cacheFactory
174+
*
175+
* @description
176+
* Get access to a cache object by the `cacheId` used when it was created.
177+
*
178+
* @param {string} cacheId Name or id of a cache to access.
179+
* @returns {object} Cache object identified by the cacheId or undefined if no such cache.
180+
*/
147181
cacheFactory.get = function(cacheId) {
148182
return caches[cacheId];
149183
};

0 commit comments

Comments
 (0)