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

Function cacheFactory

lib/test/angular/1.5.0/angular.js:6203–6430  ·  view source on GitHub ↗
(cacheId, options)

Source from the content-addressed store, hash-verified

6201 var caches = {};
6202
6203 function cacheFactory(cacheId, options) {
6204 if (cacheId in caches) {
6205 throw minErr('$cacheFactory')('iid', "CacheId '{0}' is already taken!", cacheId);
6206 }
6207
6208 var size = 0,
6209 stats = extend({}, options, {id: cacheId}),
6210 data = createMap(),
6211 capacity = (options && options.capacity) || Number.MAX_VALUE,
6212 lruHash = createMap(),
6213 freshEnd = null,
6214 staleEnd = null;
6215
6216 /**
6217 * @ngdoc type
6218 * @name $cacheFactory.Cache
6219 *
6220 * @description
6221 * A cache object used to store and retrieve data, primarily used by
6222 * {@link $http $http} and the {@link ng.directive:script script} directive to cache
6223 * templates and other data.
6224 *
6225 * ```js
6226 * angular.module('superCache')
6227 * .factory('superCache', ['$cacheFactory', function($cacheFactory) {
6228 * return $cacheFactory('super-cache');
6229 * }]);
6230 * ```
6231 *
6232 * Example test:
6233 *
6234 * ```js
6235 * it('should behave like a cache', inject(function(superCache) {
6236 * superCache.put('key', 'value');
6237 * superCache.put('another key', 'another value');
6238 *
6239 * expect(superCache.info()).toEqual({
6240 * id: 'super-cache',
6241 * size: 2
6242 * });
6243 *
6244 * superCache.remove('another key');
6245 * expect(superCache.get('another key')).toBeUndefined();
6246 *
6247 * superCache.removeAll();
6248 * expect(superCache.info()).toEqual({
6249 * id: 'super-cache',
6250 * size: 0
6251 * });
6252 * }));
6253 * ```
6254 */
6255 return caches[cacheId] = {
6256
6257 /**
6258 * @ngdoc method
6259 * @name $cacheFactory.Cache#put
6260 * @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