Add palette color cache object back to core (fix #1350) (#1395)

This commit is contained in:
Erik Ziegler 2020-01-27 10:12:07 +01:00 committed by GitHub
parent 3d3cfb1b41
commit a1b78afdb9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 39 additions and 1 deletions

View File

@ -1,3 +1,4 @@
import { api } from 'dicomweb-client';
import DICOMWeb from '../../../DICOMWeb';
const WADOProxy = {
@ -21,6 +22,43 @@ function parseFloatArray(obj) {
return result;
}
/**
* Simple cache schema for retrieved color palettes.
*/
const paletteColorCache = {
count: 0,
maxAge: 24 * 60 * 60 * 1000, // 24h cache?
entries: {},
isValidUID: function(paletteUID) {
return typeof paletteUID === 'string' && paletteUID.length > 0;
},
get: function(paletteUID) {
let entry = null;
if (this.entries.hasOwnProperty(paletteUID)) {
entry = this.entries[paletteUID];
// check how the entry is...
if (Date.now() - entry.time > this.maxAge) {
// entry is too old... remove entry.
delete this.entries[paletteUID];
this.count--;
entry = null;
}
}
return entry;
},
add: function(entry) {
if (this.isValidUID(entry.uid)) {
let paletteUID = entry.uid;
if (this.entries.hasOwnProperty(paletteUID) !== true) {
this.count++; // increment cache entry count...
}
entry.time = Date.now();
this.entries[paletteUID] = entry;
// @TODO: Add logic to get rid of old entries and reduce memory usage...
}
},
};
/**
* Create a plain JS object that describes a study (a study descriptor object)
* @param {Object} server Object with server configuration parameters

View File

@ -19,7 +19,7 @@ const DICOMFileLoader = new (class extends FileLoader {
dicomData.meta
);
} catch (e) {
console.log('Error on getting dicom file dataset. It defaults to empty');
console.error('Error reading dicom file', e);
}
// Set imageId on dataset to be consumed later on
dataset.imageId = imageId;