MCPcopy Create free account
hub / github.com/EricSimons/ionic-course / cacheFactory

Function cacheFactory

code/songhop/www/lib/angular/angular.js:5391–5616  ·  view source on GitHub ↗
(cacheId, options)

Source from the content-addressed store, hash-verified

5389 var caches = {};
5390
5391 function cacheFactory(cacheId, options) {
5392 if (cacheId in caches) {
5393 throw minErr('$cacheFactory')('iid', "CacheId '{0}' is already taken!", cacheId);
5394 }
5395
5396 var size = 0,
5397 stats = extend({}, options, {id: cacheId}),
5398 data = {},
5399 capacity = (options && options.capacity) || Number.MAX_VALUE,
5400 lruHash = {},
5401 freshEnd = null,
5402 staleEnd = null;
5403
5404 /**
5405 * @ngdoc type
5406 * @name $cacheFactory.Cache
5407 *
5408 * @description
5409 * A cache object used to store and retrieve data, primarily used by
5410 * {@link $http $http} and the {@link ng.directive:script script} directive to cache
5411 * templates and other data.
5412 *
5413 * ```js
5414 * angular.module('superCache')
5415 * .factory('superCache', ['$cacheFactory', function($cacheFactory) {
5416 * return $cacheFactory('super-cache');
5417 * }]);
5418 * ```
5419 *
5420 * Example test:
5421 *
5422 * ```js
5423 * it('should behave like a cache', inject(function(superCache) {
5424 * superCache.put('key', 'value');
5425 * superCache.put('another key', 'another value');
5426 *
5427 * expect(superCache.info()).toEqual({
5428 * id: 'super-cache',
5429 * size: 2
5430 * });
5431 *
5432 * superCache.remove('another key');
5433 * expect(superCache.get('another key')).toBeUndefined();
5434 *
5435 * superCache.removeAll();
5436 * expect(superCache.info()).toEqual({
5437 * id: 'super-cache',
5438 * size: 0
5439 * });
5440 * }));
5441 * ```
5442 */
5443 return caches[cacheId] = {
5444
5445 /**
5446 * @ngdoc method
5447 * @name $cacheFactory.Cache#put
5448 * @kind function

Callers

nothing calls this directly

Calls 5

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

Tested by

no test coverage detected