| 6840 | var caches = {}; |
| 6841 | |
| 6842 | function cacheFactory(cacheId, options) { |
| 6843 | if (cacheId in caches) { |
| 6844 | throw minErr('$cacheFactory')('iid', 'CacheId \'{0}\' is already taken!', cacheId); |
| 6845 | } |
| 6846 | |
| 6847 | var size = 0, |
| 6848 | stats = extend({}, options, {id: cacheId}), |
| 6849 | data = createMap(), |
| 6850 | capacity = (options && options.capacity) || Number.MAX_VALUE, |
| 6851 | lruHash = createMap(), |
| 6852 | freshEnd = null, |
| 6853 | staleEnd = null; |
| 6854 | |
| 6855 | /** |
| 6856 | * @ngdoc type |
| 6857 | * @name $cacheFactory.Cache |
| 6858 | * |
| 6859 | * @description |
| 6860 | * A cache object used to store and retrieve data, primarily used by |
| 6861 | * {@link $templateRequest $templateRequest} and the {@link ng.directive:script script} |
| 6862 | * directive to cache templates and other data. |
| 6863 | * |
| 6864 | * ```js |
| 6865 | * angular.module('superCache') |
| 6866 | * .factory('superCache', ['$cacheFactory', function($cacheFactory) { |
| 6867 | * return $cacheFactory('super-cache'); |
| 6868 | * }]); |
| 6869 | * ``` |
| 6870 | * |
| 6871 | * Example test: |
| 6872 | * |
| 6873 | * ```js |
| 6874 | * it('should behave like a cache', inject(function(superCache) { |
| 6875 | * superCache.put('key', 'value'); |
| 6876 | * superCache.put('another key', 'another value'); |
| 6877 | * |
| 6878 | * expect(superCache.info()).toEqual({ |
| 6879 | * id: 'super-cache', |
| 6880 | * size: 2 |
| 6881 | * }); |
| 6882 | * |
| 6883 | * superCache.remove('another key'); |
| 6884 | * expect(superCache.get('another key')).toBeUndefined(); |
| 6885 | * |
| 6886 | * superCache.removeAll(); |
| 6887 | * expect(superCache.info()).toEqual({ |
| 6888 | * id: 'super-cache', |
| 6889 | * size: 0 |
| 6890 | * }); |
| 6891 | * })); |
| 6892 | * ``` |
| 6893 | */ |
| 6894 | return (caches[cacheId] = { |
| 6895 | |
| 6896 | /** |
| 6897 | * @ngdoc method |
| 6898 | * @name $cacheFactory.Cache#put |
| 6899 | * @kind function |