From 06a9972228e2fa6740824e7a3470de69bf5ee332 Mon Sep 17 00:00:00 2001 From: Itamar Rogel Date: Sun, 30 Jun 2013 21:27:42 +0300 Subject: docs($cacheFactory): show that you can access existing caches --- src/ng/cacheFactory.js | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) (limited to 'src/ng/cacheFactory.js') diff --git a/src/ng/cacheFactory.js b/src/ng/cacheFactory.js index 7fcf81ff..fb4c2c6b 100644 --- a/src/ng/cacheFactory.js +++ b/src/ng/cacheFactory.js @@ -3,7 +3,20 @@ * @name ng.$cacheFactory * * @description - * Factory that constructs cache objects. + * Factory that constructs cache objects and gives access to them. + * + *
+ * 
+ *  var cache = $cacheFactory('cacheId');
+ *  expect($cacheFactory.get('cacheId')).toBe(cache);
+ *  expect($cacheFactory.get('noSuchCacheId')).not.toBeDefined();
+ *
+ *  cache.put("key", "value");
+ *  cache.put("another key", "another value");
+ * 
+ *  expect(cache.info()).toEqual({id: 'cacheId', size: 2}); // Since we've specified no options on creation
+ * 
+ * 
  *
  *
  * @param {string} cacheId Name or id of the newly created cache.
@@ -137,6 +150,16 @@ function $CacheFactoryProvider() {
     }
 
 
+  /**
+   * @ngdoc method
+   * @name ng.$cacheFactory#info
+   * @methodOf ng.$cacheFactory
+   *
+   * @description
+   * Get information about all the of the caches that have been created
+   *
+   * @returns {Object} - key-value map of `cacheId` to the result of calling `cache#info`
+   */
     cacheFactory.info = function() {
       var info = {};
       forEach(caches, function(cache, cacheId) {
@@ -146,6 +169,17 @@ function $CacheFactoryProvider() {
     };
 
 
+  /**
+   * @ngdoc method
+   * @name ng.$cacheFactory#get
+   * @methodOf ng.$cacheFactory
+   *
+   * @description
+   * Get access to a cache object by the `cacheId` used when it was created.
+   *
+   * @param {string} cacheId Name or id of a cache to access.
+   * @returns {object} Cache object identified by the cacheId or undefined if no such cache.
+   */
     cacheFactory.get = function(cacheId) {
       return caches[cacheId];
     };
-- 
cgit v1.2.3