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

Function cacheFactory

test/angular/1.7/angular.js:6940–7167  ·  view source on GitHub ↗
(cacheId, options)

Source from the content-addressed store, hash-verified

6938 var caches = {};
6939
6940 function cacheFactory(cacheId, options) {
6941 if (cacheId in caches) {
6942 throw minErr('$cacheFactory')('iid', 'CacheId \'{0}\' is already taken!', cacheId);
6943 }
6944
6945 var size = 0,
6946 stats = extend({}, options, {id: cacheId}),
6947 data = createMap(),
6948 capacity = (options && options.capacity) || Number.MAX_VALUE,
6949 lruHash = createMap(),
6950 freshEnd = null,
6951 staleEnd = null;
6952
6953 /**
6954 * @ngdoc type
6955 * @name $cacheFactory.Cache
6956 *
6957 * @description
6958 * A cache object used to store and retrieve data, primarily used by
6959 * {@link $templateRequest $templateRequest} and the {@link ng.directive:script script}
6960 * directive to cache templates and other data.
6961 *
6962 * ```js
6963 * angular.module('superCache')
6964 * .factory('superCache', ['$cacheFactory', function($cacheFactory) {
6965 * return $cacheFactory('super-cache');
6966 * }]);
6967 * ```
6968 *
6969 * Example test:
6970 *
6971 * ```js
6972 * it('should behave like a cache', inject(function(superCache) {
6973 * superCache.put('key', 'value');
6974 * superCache.put('another key', 'another value');
6975 *
6976 * expect(superCache.info()).toEqual({
6977 * id: 'super-cache',
6978 * size: 2
6979 * });
6980 *
6981 * superCache.remove('another key');
6982 * expect(superCache.get('another key')).toBeUndefined();
6983 *
6984 * superCache.removeAll();
6985 * expect(superCache.info()).toEqual({
6986 * id: 'super-cache',
6987 * size: 0
6988 * });
6989 * }));
6990 * ```
6991 */
6992 return (caches[cacheId] = {
6993
6994 /**
6995 * @ngdoc method
6996 * @name $cacheFactory.Cache#put
6997 * @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