MCPcopy
hub / github.com/angular-ui/ui-grid / cacheFactory

Function cacheFactory

lib/test/angular/1.4.3/angular.js:5788–6013  ·  view source on GitHub ↗
(cacheId, options)

Source from the content-addressed store, hash-verified

5786 var caches = {};
5787
5788 function cacheFactory(cacheId, options) {
5789 if (cacheId in caches) {
5790 throw minErr('$cacheFactory')('iid', "CacheId '{0}' is already taken!", cacheId);
5791 }
5792
5793 var size = 0,
5794 stats = extend({}, options, {id: cacheId}),
5795 data = {},
5796 capacity = (options && options.capacity) || Number.MAX_VALUE,
5797 lruHash = {},
5798 freshEnd = null,
5799 staleEnd = null;
5800
5801 /**
5802 * @ngdoc type
5803 * @name $cacheFactory.Cache
5804 *
5805 * @description
5806 * A cache object used to store and retrieve data, primarily used by
5807 * {@link $http $http} and the {@link ng.directive:script script} directive to cache
5808 * templates and other data.
5809 *
5810 * ```js
5811 * angular.module('superCache')
5812 * .factory('superCache', ['$cacheFactory', function($cacheFactory) {
5813 * return $cacheFactory('super-cache');
5814 * }]);
5815 * ```
5816 *
5817 * Example test:
5818 *
5819 * ```js
5820 * it('should behave like a cache', inject(function(superCache) {
5821 * superCache.put('key', 'value');
5822 * superCache.put('another key', 'another value');
5823 *
5824 * expect(superCache.info()).toEqual({
5825 * id: 'super-cache',
5826 * size: 2
5827 * });
5828 *
5829 * superCache.remove('another key');
5830 * expect(superCache.get('another key')).toBeUndefined();
5831 *
5832 * superCache.removeAll();
5833 * expect(superCache.info()).toEqual({
5834 * id: 'super-cache',
5835 * size: 0
5836 * });
5837 * }));
5838 * ```
5839 */
5840 return caches[cacheId] = {
5841
5842 /**
5843 * @ngdoc method
5844 * @name $cacheFactory.Cache#put
5845 * @kind function

Callers

nothing calls this directly

Calls 5

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

Tested by

no test coverage detected