MCPcopy
hub / github.com/angular-ui/ui-router / cacheFactory

Function cacheFactory

test/angular/1.4/angular.js:6163–6390  ·  view source on GitHub ↗
(cacheId, options)

Source from the content-addressed store, hash-verified

6161 var caches = {};
6162
6163 function cacheFactory(cacheId, options) {
6164 if (cacheId in caches) {
6165 throw minErr('$cacheFactory')('iid', "CacheId '{0}' is already taken!", cacheId);
6166 }
6167
6168 var size = 0,
6169 stats = extend({}, options, {id: cacheId}),
6170 data = createMap(),
6171 capacity = (options && options.capacity) || Number.MAX_VALUE,
6172 lruHash = createMap(),
6173 freshEnd = null,
6174 staleEnd = null;
6175
6176 /**
6177 * @ngdoc type
6178 * @name $cacheFactory.Cache
6179 *
6180 * @description
6181 * A cache object used to store and retrieve data, primarily used by
6182 * {@link $http $http} and the {@link ng.directive:script script} directive to cache
6183 * templates and other data.
6184 *
6185 * ```js
6186 * angular.module('superCache')
6187 * .factory('superCache', ['$cacheFactory', function($cacheFactory) {
6188 * return $cacheFactory('super-cache');
6189 * }]);
6190 * ```
6191 *
6192 * Example test:
6193 *
6194 * ```js
6195 * it('should behave like a cache', inject(function(superCache) {
6196 * superCache.put('key', 'value');
6197 * superCache.put('another key', 'another value');
6198 *
6199 * expect(superCache.info()).toEqual({
6200 * id: 'super-cache',
6201 * size: 2
6202 * });
6203 *
6204 * superCache.remove('another key');
6205 * expect(superCache.get('another key')).toBeUndefined();
6206 *
6207 * superCache.removeAll();
6208 * expect(superCache.info()).toEqual({
6209 * id: 'super-cache',
6210 * size: 0
6211 * });
6212 * }));
6213 * ```
6214 */
6215 return caches[cacheId] = {
6216
6217 /**
6218 * @ngdoc method
6219 * @name $cacheFactory.Cache#put
6220 * @kind function

Callers

nothing calls this directly

Calls 6

minErrFunction · 0.70
extendFunction · 0.70
createMapFunction · 0.70
isUndefinedFunction · 0.70
refreshFunction · 0.70
linkFunction · 0.70

Tested by

no test coverage detected