(cacheId, options)
| 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 |
nothing calls this directly
no test coverage detected