(cacheId, options)
| 5448 | var caches = {}; |
| 5449 | |
| 5450 | function cacheFactory(cacheId, options) { |
| 5451 | if (cacheId in caches) { |
| 5452 | throw minErr('$cacheFactory')('iid', "CacheId '{0}' is already taken!", cacheId); |
| 5453 | } |
| 5454 | |
| 5455 | var size = 0, |
| 5456 | stats = extend({}, options, {id: cacheId}), |
| 5457 | data = {}, |
| 5458 | capacity = (options && options.capacity) || Number.MAX_VALUE, |
| 5459 | lruHash = {}, |
| 5460 | freshEnd = null, |
| 5461 | staleEnd = null; |
| 5462 | |
| 5463 | /** |
| 5464 | * @ngdoc type |
| 5465 | * @name $cacheFactory.Cache |
| 5466 | * |
| 5467 | * @description |
| 5468 | * A cache object used to store and retrieve data, primarily used by |
| 5469 | * {@link $http $http} and the {@link ng.directive:script script} directive to cache |
| 5470 | * templates and other data. |
| 5471 | * |
| 5472 | * ```js |
| 5473 | * angular.module('superCache') |
| 5474 | * .factory('superCache', ['$cacheFactory', function($cacheFactory) { |
| 5475 | * return $cacheFactory('super-cache'); |
| 5476 | * }]); |
| 5477 | * ``` |
| 5478 | * |
| 5479 | * Example test: |
| 5480 | * |
| 5481 | * ```js |
| 5482 | * it('should behave like a cache', inject(function(superCache) { |
| 5483 | * superCache.put('key', 'value'); |
| 5484 | * superCache.put('another key', 'another value'); |
| 5485 | * |
| 5486 | * expect(superCache.info()).toEqual({ |
| 5487 | * id: 'super-cache', |
| 5488 | * size: 2 |
| 5489 | * }); |
| 5490 | * |
| 5491 | * superCache.remove('another key'); |
| 5492 | * expect(superCache.get('another key')).toBeUndefined(); |
| 5493 | * |
| 5494 | * superCache.removeAll(); |
| 5495 | * expect(superCache.info()).toEqual({ |
| 5496 | * id: 'super-cache', |
| 5497 | * size: 0 |
| 5498 | * }); |
| 5499 | * })); |
| 5500 | * ``` |
| 5501 | */ |
| 5502 | return caches[cacheId] = { |
| 5503 | |
| 5504 | /** |
| 5505 | * @ngdoc method |
| 5506 | * @name $cacheFactory.Cache#put |
| 5507 | * @kind function |
nothing calls this directly
no test coverage detected