MCPcopy Index your code
hub / github.com/angular-ui/ui-router / cacheFactory

Function cacheFactory

test/angular/1.2/angular.js:4856–5081  ·  view source on GitHub ↗
(cacheId, options)

Source from the content-addressed store, hash-verified

4854 var caches = {};
4855
4856 function cacheFactory(cacheId, options) {
4857 if (cacheId in caches) {
4858 throw minErr('$cacheFactory')('iid', "CacheId '{0}' is already taken!", cacheId);
4859 }
4860
4861 var size = 0,
4862 stats = extend({}, options, {id: cacheId}),
4863 data = {},
4864 capacity = (options && options.capacity) || Number.MAX_VALUE,
4865 lruHash = {},
4866 freshEnd = null,
4867 staleEnd = null;
4868
4869 /**
4870 * @ngdoc type
4871 * @name $cacheFactory.Cache
4872 *
4873 * @description
4874 * A cache object used to store and retrieve data, primarily used by
4875 * {@link $http $http} and the {@link ng.directive:script script} directive to cache
4876 * templates and other data.
4877 *
4878 * ```js
4879 * angular.module('superCache')
4880 * .factory('superCache', ['$cacheFactory', function($cacheFactory) {
4881 * return $cacheFactory('super-cache');
4882 * }]);
4883 * ```
4884 *
4885 * Example test:
4886 *
4887 * ```js
4888 * it('should behave like a cache', inject(function(superCache) {
4889 * superCache.put('key', 'value');
4890 * superCache.put('another key', 'another value');
4891 *
4892 * expect(superCache.info()).toEqual({
4893 * id: 'super-cache',
4894 * size: 2
4895 * });
4896 *
4897 * superCache.remove('another key');
4898 * expect(superCache.get('another key')).toBeUndefined();
4899 *
4900 * superCache.removeAll();
4901 * expect(superCache.info()).toEqual({
4902 * id: 'super-cache',
4903 * size: 0
4904 * });
4905 * }));
4906 * ```
4907 */
4908 return caches[cacheId] = {
4909
4910 /**
4911 * @ngdoc method
4912 * @name $cacheFactory.Cache#put
4913 * @kind function

Callers

nothing calls this directly

Calls 5

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

Tested by

no test coverage detected