UNPKG

knowhow-server

Version:

A personal workflow engine that can manage and use any network connected host

57 lines (52 loc) 4.34 kB
<a href="http://github.com/angular/angular.js/tree/v1.2.9/src/ng/cacheFactory.js#L3" class="view-source btn btn-action"><i class="icon-zoom-in"> </i> View source</a><a href="http://github.com/angular/angular.js/edit/master/src/ng/cacheFactory.js" class="improve-docs btn btn-primary"><i class="icon-edit"> </i> Improve this doc</a><h1><code ng:non-bindable="">$cacheFactory</code> <div><span class="hint">service in module <code ng:non-bindable="">ng</code> </span> </div> </h1> <div><h2 id="description">Description</h2> <div class="description"><div class="ng-cachefactory-page"><p>Factory that constructs cache objects and gives access to them.</p> <pre class="prettyprint linenums"> 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}); </pre> </div></div> <h2 id="usage">Usage</h2> <div class="usage"><pre class="prettyprint linenums">$cacheFactory(cacheId[, options]);</pre> <h4 id="usage_parameters">Parameters</h4><table class="variables-matrix table table-bordered table-striped"><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><div class="ng-cachefactory-page"><p>Name or id of the newly created cache.</p> </div></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><div class="ng-cachefactory-page"><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> </div></td></tr></tbody></table><h4 id="usage_returns">Returns</h4><table class="variables-matrix"><tr><td><a href="" class="label type-hint type-hint-object">object</a></td><td><div class="ng-cachefactory-page"><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> </div></td></tr></table></div> <div class="member method"><h2 id="methods">Methods</h2> <ul class="methods"><li><h3 id="methods_get">get(cacheId)</h3> <div class="get"><div class="ng-cachefactory-get-page"><p>Get access to a cache object by the <code>cacheId</code> used when it was created.</p> </div><h5 id="methods_get_parameters">Parameters</h5><table class="variables-matrix table table-bordered table-striped"><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><div class="ng-cachefactory-get-page"><p>Name or id of a cache to access.</p> </div></td></tr></tbody></table><h5 id="methods_get_returns">Returns</h5><table class="variables-matrix"><tr><td><a href="" class="label type-hint type-hint-object">object</a></td><td><div class="ng-cachefactory-get-page"><p>Cache object identified by the cacheId or undefined if no such cache.</p> </div></td></tr></table></div> </li> <li><h3 id="methods_info">info()</h3> <div class="info"><div class="ng-cachefactory-info-page"><p>Get information about all the of the caches that have been created</p> </div><h5 id="methods_info_returns">Returns</h5><table class="variables-matrix"><tr><td><a href="" class="label type-hint type-hint-object">Object</a></td><td><div class="ng-cachefactory-info-page"><ul> <li>key-value map of <code>cacheId</code> to the result of calling <code>cache#info</code></li> </ul> </div></td></tr></table></div> </li> </ul> </div> </div>