EVOLUTION-MANAGER
Edit File: $cacheFactory.html
<a href='https://github.com/angular/angular.js/edit/v1.3.x/src/ng/cacheFactory.js?message=docs($cacheFactory)%3A%20describe%20your%20change...#L3' class='improve-docs btn btn-primary'><i class="glyphicon glyphicon-edit"> </i>Improve this Doc</a> <a href='https://github.com/angular/angular.js/tree/v1.3.9/src/ng/cacheFactory.js#L3' class='view-source pull-right btn btn-primary'> <i class="glyphicon glyphicon-zoom-in"> </i>View Source </a> <header class="api-profile-header"> <h1 class="api-profile-header-heading">$cacheFactory</h1> <ol class="api-profile-header-structure naked-list step-list"> <li> - service in module <a href="api/ng">ng</a> </li> </ol> </header> <div class="api-profile-description"> <p>Factory that constructs <a href="api/ng/type/$cacheFactory.Cache">Cache</a> objects and gives access to them.</p> <pre><code class="lang-js">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"); // We've specified no options on creation expect(cache.info()).toEqual({id: 'cacheId', size: 2}); </code></pre> </div> <div> <h2 id="usage">Usage</h2> <p><code>$cacheFactory(cacheId, [options]);</code></p> <section class="api-section"> <h3>Arguments</h3> <table class="variables-matrix input-arguments"> <thead> <tr> <th>Param</th> <th>Type</th> <th>Details</th> </tr> </thead> <tbody> <tr> <td> cacheId </td> <td> <a href="" class="label type-hint type-hint-string">string</a> </td> <td> <p>Name or id of the newly created cache.</p> </td> </tr> <tr> <td> options <div><em>(optional)</em></div> </td> <td> <a href="" class="label type-hint type-hint-object">object</a> </td> <td> <p>Options object that specifies the cache behavior. Properties:</p> <ul> <li><code>{number=}</code> <code>capacity</code> — turns the cache into LRU cache.</li> </ul> </td> </tr> </tbody> </table> </section> <h3>Returns</h3> <table class="variables-matrix return-arguments"> <tr> <td><a href="" class="label type-hint type-hint-object">object</a></td> <td><p>Newly created cache object with the following set of methods:</p> <ul> <li><code>{object}</code> <code>info()</code> — Returns id, size, and options of cache.</li> <li><code>{{*}}</code> <code>put({string} key, {*} value)</code> — Puts a new key-value pair into the cache and returns it.</li> <li><code>{{*}}</code> <code>get({string} key)</code> — Returns cached value for <code>key</code> or undefined for cache miss.</li> <li><code>{void}</code> <code>remove({string} key)</code> — Removes a key-value pair from the cache.</li> <li><code>{void}</code> <code>removeAll()</code> — Removes all cached values.</li> <li><code>{void}</code> <code>destroy()</code> — Removes references to this cache from $cacheFactory.</li> </ul> </td> </tr> </table> <h2>Methods</h2> <ul class="methods"> <li id="info"> <h3><p><code>info();</code></p> </h3> <div><p>Get information about all the caches that have been created</p> </div> <h4>Returns</h4> <table class="variables-matrix return-arguments"> <tr> <td><a href="" class="label type-hint type-hint-object">Object</a></td> <td><ul> <li>key-value map of <code>cacheId</code> to the result of calling <code>cache#info</code></li> </ul> </td> </tr> </table> </li> <li id="get"> <h3><p><code>get(cacheId);</code></p> </h3> <div><p>Get access to a cache object by the <code>cacheId</code> used when it was created.</p> </div> <h4>Parameters</h4> <table class="variables-matrix input-arguments"> <thead> <tr> <th>Param</th> <th>Type</th> <th>Details</th> </tr> </thead> <tbody> <tr> <td> cacheId </td> <td> <a href="" class="label type-hint type-hint-string">string</a> </td> <td> <p>Name or id of a cache to access.</p> </td> </tr> </tbody> </table> <h4>Returns</h4> <table class="variables-matrix return-arguments"> <tr> <td><a href="" class="label type-hint type-hint-object">object</a></td> <td><p>Cache object identified by the cacheId or undefined if no such cache.</p> </td> </tr> </table> </li> </ul> <h2 id="example">Example</h2><p> <div> <a ng-click="openPlunkr('examples/example-example50')" class="btn pull-right"> <i class="glyphicon glyphicon-edit"> </i> Edit in Plunker</a> <div class="runnable-example" path="examples/example-example50" module="cacheExampleApp"> <div class="runnable-example-file" name="index.html" language="html" type="html"> <pre><code><div ng-controller="CacheController"> <input ng-model="newCacheKey" placeholder="Key"> <input ng-model="newCacheValue" placeholder="Value"> <button ng-click="put(newCacheKey, newCacheValue)">Cache</button> <p ng-if="keys.length">Cached Values</p> <div ng-repeat="key in keys"> <span ng-bind="key"></span> <span>: </span> <b ng-bind="cache.get(key)"></b> </div> <p>Cache Info</p> <div ng-repeat="(key, value) in cache.info()"> <span ng-bind="key"></span> <span>: </span> <b ng-bind="value"></b> </div> </div></code></pre> </div> <div class="runnable-example-file" name="script.js" language="js" type="js"> <pre><code>angular.module('cacheExampleApp', []). controller('CacheController', ['$scope', '$cacheFactory', function($scope, $cacheFactory) { $scope.keys = []; $scope.cache = $cacheFactory('cacheId'); $scope.put = function(key, value) { if ($scope.cache.get(key) === undefined) { $scope.keys.push(key); } $scope.cache.put(key, value === undefined ? null : value); }; }]);</code></pre> </div> <div class="runnable-example-file" name="style.css" language="css" type="css"> <pre><code>p { margin: 10px 0 3px; }</code></pre> </div> <iframe class="runnable-example-frame" src="examples/example-example50/index.html" name="example-example50"></iframe> </div> </div> </p> </div>