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

Commit 06a9972

Browse files
itamarropetebacondarwin
authored andcommitted
docs($cacheFactory): show that you can access existing caches
1 parent 1532ec1 commit 06a9972

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.
@@ -137,6 +150,16 @@ function $CacheFactoryProvider() {
137150
}
138151

139152

153+
/**
154+
* @ngdoc method
155+
* @name ng.$cacheFactory#info
156+
* @methodOf ng.$cacheFactory
157+
*
158+
* @description
159+
* Get information about all the of the caches that have been created
160+
*
161+
* @returns {Object} - key-value map of `cacheId` to the result of calling `cache#info`
162+
*/
140163
cacheFactory.info = function() {
141164
var info = {};
142165
forEach(caches, function(cache, cacheId) {
@@ -146,6 +169,17 @@ function $CacheFactoryProvider() {
146169
};
147170

148171

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

0 commit comments

Comments
 (0)