(cacheId, options)
| 5904 | var caches = {}; |
| 5905 | |
| 5906 | function cacheFactory(cacheId, options) { |
| 5907 | if (cacheId in caches) { |
| 5908 | throw minErr('$cacheFactory')('iid', "CacheId '{0}' is already taken!", cacheId); |
| 5909 | } |
| 5910 | |
| 5911 | var size = 0, |
| 5912 | stats = extend({}, options, {id: cacheId}), |
| 5913 | data = {}, |
| 5914 | capacity = (options && options.capacity) || Number.MAX_VALUE, |
| 5915 | lruHash = {}, |
| 5916 | freshEnd = null, |
| 5917 | staleEnd = null; |
| 5918 | |
| 5919 | /** |
| 5920 | * @ngdoc type |
| 5921 | * @name $cacheFactory.Cache |
| 5922 | * |
| 5923 | * @description |
| 5924 | * A cache object used to store and retrieve data, primarily used by |
| 5925 | * {@link $http $http} and the {@link ng.directive:script script} directive to cache |
| 5926 | * templates and other data. |
| 5927 | * |
| 5928 | * ```js |
| 5929 | * angular.module('superCache') |
| 5930 | * .factory('superCache', ['$cacheFactory', function($cacheFactory) { |
| 5931 | * return $cacheFactory('super-cache'); |
| 5932 | * }]); |
| 5933 | * ``` |
| 5934 | * |
| 5935 | * Example test: |
| 5936 | * |
| 5937 | * ```js |
| 5938 | * it('should behave like a cache', inject(function(superCache) { |
| 5939 | * superCache.put('key', 'value'); |
| 5940 | * superCache.put('another key', 'another value'); |
| 5941 | * |
| 5942 | * expect(superCache.info()).toEqual({ |
| 5943 | * id: 'super-cache', |
| 5944 | * size: 2 |
| 5945 | * }); |
| 5946 | * |
| 5947 | * superCache.remove('another key'); |
| 5948 | * expect(superCache.get('another key')).toBeUndefined(); |
| 5949 | * |
| 5950 | * superCache.removeAll(); |
| 5951 | * expect(superCache.info()).toEqual({ |
| 5952 | * id: 'super-cache', |
| 5953 | * size: 0 |
| 5954 | * }); |
| 5955 | * })); |
| 5956 | * ``` |
| 5957 | */ |
| 5958 | return caches[cacheId] = { |
| 5959 | |
| 5960 | /** |
| 5961 | * @ngdoc method |
| 5962 | * @name $cacheFactory.Cache#put |
| 5963 | * @kind function |
nothing calls this directly
no test coverage detected