diff --git a/src/imageCache.js b/src/imageCache.js index 4f9031f8..750971d6 100644 --- a/src/imageCache.js +++ b/src/imageCache.js @@ -15,6 +15,11 @@ const imageCacheDict = {}; // Array of cachedImage objects export const cachedImages = []; +/** Sets the maximum size of cache and purges cache contents if necessary. + * + * @param {number} numBytes The maximun size that the cache should occupy. + * @returns {void} + */ export function setMaximumSizeBytes (numBytes) { if (numBytes === undefined) { throw new Error('setMaximumSizeBytes: parameter numBytes must not be undefined'); @@ -30,6 +35,10 @@ export function setMaximumSizeBytes (numBytes) { purgeCacheIfNecessary(); } +/** + * Purges the cache if size exceeds maximum + * @returns {void} + */ function purgeCacheIfNecessary () { // If max cache size has not been exceeded, do nothing if (cacheSizeInBytes <= maximumSizeInBytes) { @@ -65,6 +74,13 @@ function purgeCacheIfNecessary () { triggerEvent(events, EVENTS.IMAGE_CACHE_FULL, cacheInfo); } +/** + * Puts a new image loader into the cache + * + * @param {string} imageId ImageId of the image loader + * @param {Object} imageLoadObject The object that is loading or loaded the image + * @returns {void} + */ export function putImageLoadObject (imageId, imageLoadObject) { if (imageId === undefined) { throw new Error('putImageLoadObject: imageId must not be undefined'); @@ -128,6 +144,12 @@ export function putImageLoadObject (imageId, imageLoadObject) { }); } +/** + * Retuns the object that is loading a given imageId + * + * @param {string} imageId Image ID + * @returns {void} + */ export function getImageLoadObject (imageId) { if (imageId === undefined) { throw new Error('getImageLoadObject: imageId must not be undefined'); @@ -144,6 +166,12 @@ export function getImageLoadObject (imageId) { return cachedImage.imageLoadObject; } +/** + * Removes the image loader associated with a given Id from the cache + * + * @param {string} imageId Image ID + * @returns {void} + */ export function removeImageLoadObject (imageId) { if (imageId === undefined) { throw new Error('removeImageLoadObject: imageId must not be undefined'); @@ -168,6 +196,18 @@ export function removeImageLoadObject (imageId) { delete imageCacheDict[imageId]; } +/** + * @typedef {Object} CacheInformation + * @property {number} maximumSizeInBytes The maximum size of the cache in bytes + * @property {number} cacheSizeInBytes Currently occupied space in the cache in bytes + * @property {number} numberOfImagesCached Number of ImageLoaders in the cache + * @returns {void} + */ + +/** + * Gets the current state of the cache + * @returns {void} + */ export function getCacheInfo () { return { maximumSizeInBytes, @@ -178,6 +218,12 @@ export function getCacheInfo () { // This method should only be called by `removeImageLoadObject` because it's // The one that knows how to deal with shared cache keys and cache size. +/** + * INTERNAL: Removes and ImageLoader from the cache + * + * @param {Object} imageLoadObject Image Loader Object to remove + * @returns {void} + */ function decache (imageLoadObject) { imageLoadObject.promise.then( function () { @@ -193,6 +239,10 @@ function decache (imageLoadObject) { ); } +/** + * Removes all images from cache + * @returns {void} + */ export function purgeCache () { while (cachedImages.length > 0) { const removedCachedImage = cachedImages[0]; @@ -201,6 +251,13 @@ export function purgeCache () { } } +/** + * Updates the space than an image is using in the cache + * + * @param {string} imageId Image ID + * @param {number} newCacheSize New image size + * @returns {void} + */ export function changeImageIdCacheSize (imageId, newCacheSize) { const cacheEntry = imageCacheDict[imageId]; diff --git a/src/internal/drawImage.js b/src/internal/drawImage.js index 96042fb6..06049f74 100644 --- a/src/internal/drawImage.js +++ b/src/internal/drawImage.js @@ -2,7 +2,7 @@ * Internal API function to draw an image to a given enabled element * * @param {EnabledElement} enabledElement The Cornerstone Enabled Element to redraw - * @param {Boolean} [invalidated] - true if pixel data has been invalidated and cached rendering should not be used + * @param {Boolean} [invalidated = false] - true if pixel data has been invalidated and cached rendering should not be used * @returns {void} * @memberof Internal */