©
Dieses Dokument verwendetPHP-Handbuch für chinesische WebsitesFreigeben
Factory that constructs Cache objects and gives access to them.
varcache=$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 creationexpect(cache.info()).toEqual({id:'cacheId',size:2});
$cacheFactory(cacheId,[options]);
参数 | 类型 | 详述 |
---|---|---|
cacheId | string | Name or id of the newly created cache. |
options
(可选)
|
Object | Options object that specifies the cache behavior. Properties:
|
Object | Newly created cache object with the following set of methods:
|
info();
Get information about all the caches that have been created
Object |
|
get(cacheId);
Get access to a cache object by thecacheId
used when it was created.
参数 | 类型 | 详述 |
---|---|---|
cacheId | string | Name or id of a cache to access. |
Object | Cache object identified by the cacheId or undefined if no such cache. |
ng-controller="CacheController">ng-model="newCacheKey"placeholder="Key">ng-model="newCacheValue"placeholder="Value">ng-if="keys.length">Cached Values
ng-repeat="key in keys">ng-bind="key">:ng-bind="cache.get(key)">Cache Infong-repeat="(key, value) in cache.info()">ng-bind="key">:ng-bind="value">
angular.module('cacheExampleApp',[]).controller('CacheController',['$scope','$cacheFactory',Function($scope,$cacheFactory){$scope.keys=[];$scope.cache=$cacheFactory('cacheId');$scope.put=Function(key,value){$scope.cache.put(key,value);$scope.keys.push(key);};}]);
p{margin:10px03px;}