(cacheId, options)
| 7118 | var caches = {}; |
| 7119 | |
| 7120 | function cacheFactory(cacheId, options) { |
| 7121 | if (cacheId in caches) { |
| 7122 | throw minErr('$cacheFactory')('iid', 'CacheId \'{0}\' is already taken!', cacheId); |
| 7123 | } |
| 7124 | |
| 7125 | var size = 0, |
| 7126 | stats = extend({}, options, { |
| 7127 | id: cacheId |
| 7128 | }), |
| 7129 | data = createMap(), |
| 7130 | capacity = (options && options.capacity) || Number.MAX_VALUE, |
| 7131 | lruHash = createMap(), |
| 7132 | freshEnd = null, |
| 7133 | staleEnd = null; |
| 7134 | |
| 7135 | /** |
| 7136 | * @ngdoc type |
| 7137 | * @name $cacheFactory.Cache |
| 7138 | * |
| 7139 | * @description |
| 7140 | * A cache object used to store and retrieve data, primarily used by |
| 7141 | * {@link $templateRequest $templateRequest} and the {@link ng.directive:script script} |
| 7142 | * directive to cache templates and other data. |
| 7143 | * |
| 7144 | * ```js |
| 7145 | * angular.module('superCache') |
| 7146 | * .factory('superCache', ['$cacheFactory', function($cacheFactory) { |
| 7147 | * return $cacheFactory('super-cache'); |
| 7148 | * }]); |
| 7149 | * ``` |
| 7150 | * |
| 7151 | * Example test: |
| 7152 | * |
| 7153 | * ```js |
| 7154 | * it('should behave like a cache', inject(function(superCache) { |
| 7155 | * superCache.put('key', 'value'); |
| 7156 | * superCache.put('another key', 'another value'); |
| 7157 | * |
| 7158 | * expect(superCache.info()).toEqual({ |
| 7159 | * id: 'super-cache', |
| 7160 | * size: 2 |
| 7161 | * }); |
| 7162 | * |
| 7163 | * superCache.remove('another key'); |
| 7164 | * expect(superCache.get('another key')).toBeUndefined(); |
| 7165 | * |
| 7166 | * superCache.removeAll(); |
| 7167 | * expect(superCache.info()).toEqual({ |
| 7168 | * id: 'super-cache', |
| 7169 | * size: 0 |
| 7170 | * }); |
| 7171 | * })); |
| 7172 | * ``` |
| 7173 | */ |
| 7174 | return (caches[cacheId] = { |
| 7175 | |
| 7176 | /** |
| 7177 | * @ngdoc method |
nothing calls this directly
no test coverage detected