add ArraysByKeyCache.ts (#366)

* 'add ArraysByKeyCache'
* "minor change"
This commit is contained in:
Chris-MS-896 2021-01-08 22:51:50 -06:00 committed by GitHub
parent 6627172a52
commit 2d98c5d269
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 14 deletions

View File

@ -11,7 +11,9 @@ export class ArraysByKeyCache<T> {
public constructor(maxNbElements: number) { public constructor(maxNbElements: number) {
this.maxNbElements = maxNbElements; this.maxNbElements = maxNbElements;
this.clear(); this.keyQueue = [];
this.cache = {};
this.totalElements = 0;
} }
public clear(): void { public clear(): void {
@ -58,7 +60,7 @@ export class ArraysByKeyCache<T> {
* @param startIndex * @param startIndex
* @param pageSize * @param pageSize
*/ */
public retrieve(key: string, startIndex: number, pageSize: number): T[] { public retrieve(key: string, startIndex: number, pageSize: number): T[] | null {
if (!this.cache.hasOwnProperty(key)) { if (!this.cache.hasOwnProperty(key)) {
return null; return null;
} }
@ -77,8 +79,10 @@ export class ArraysByKeyCache<T> {
private reduceCacheSize(): void { private reduceCacheSize(): void {
// remove an key and its array // remove an key and its array
const oldKey = this.keyQueue.shift(); const oldKey = this.keyQueue.shift();
this.totalElements -= this.cache[oldKey].length; if (oldKey) {
delete this.cache[oldKey]; this.totalElements -= this.cache[oldKey].length;
delete this.cache[oldKey];
}
} }
/** /**

View File

@ -12,19 +12,19 @@
"./src/Bindings/ReactBindingHandler.ts", "./src/Bindings/ReactBindingHandler.ts",
"./src/Common/ArrayHashMap.ts", "./src/Common/ArrayHashMap.ts",
"./src/Common/Constants.ts", "./src/Common/Constants.ts",
"./src/Common/DeleteFeedback.ts", "./src/Common/DeleteFeedback.ts",
"./src/Common/DocumentUtility.ts", "./src/Common/DocumentUtility.ts",
"./src/Common/EnvironmentUtility.ts", "./src/Common/EnvironmentUtility.ts",
"./src/Common/HashMap.ts", "./src/Common/HashMap.ts",
"./src/Common/HeadersUtility.ts", "./src/Common/HeadersUtility.ts",
"./src/Common/Logger.ts", "./src/Common/Logger.ts",
"./src/Common/MessageHandler.ts", "./src/Common/MessageHandler.ts",
"./src/Common/MongoUtility.ts", "./src/Common/MongoUtility.ts",
"./src/Common/ObjectCache.ts", "./src/Common/ObjectCache.ts",
"./src/Common/OfferUtility.ts", "./src/Common/OfferUtility.ts",
"./src/Common/ThemeUtility.ts", "./src/Common/ThemeUtility.ts",
"./src/Common/UrlUtility.ts", "./src/Common/UrlUtility.ts",
"./src/Common/Splitter.ts", "./src/Common/Splitter.ts",
"./src/ConfigContext.ts", "./src/ConfigContext.ts",
"./src/Contracts/ActionContracts.ts", "./src/Contracts/ActionContracts.ts",
"./src/Contracts/DataModels.ts", "./src/Contracts/DataModels.ts",
@ -41,12 +41,13 @@
"./src/Definitions/jquery.d.ts", "./src/Definitions/jquery.d.ts",
"./src/Definitions/plotly.js-cartesian-dist.d-min.ts", "./src/Definitions/plotly.js-cartesian-dist.d-min.ts",
"./src/Definitions/svg.d.ts", "./src/Definitions/svg.d.ts",
"./src/Explorer/Controls/ErrorDisplayComponent/ErrorDisplayComponent.ts", "./src/Explorer/Controls/ErrorDisplayComponent/ErrorDisplayComponent.ts",
"./src/Explorer/Controls/CollapsiblePanel/CollapsiblePanelComponent.ts", "./src/Explorer/Controls/CollapsiblePanel/CollapsiblePanelComponent.ts",
"./src/Explorer/Controls/GitHub/GitHubStyleConstants.ts", "./src/Explorer/Controls/GitHub/GitHubStyleConstants.ts",
"./src/Explorer/Controls/InputTypeahead/InputTypeahead.ts", "./src/Explorer/Controls/InputTypeahead/InputTypeahead.ts",
"./src/Explorer/Controls/SmartUi/InputUtils.ts", "./src/Explorer/Controls/SmartUi/InputUtils.ts",
"./src/Explorer/Graph/GraphExplorerComponent/__mocks__/GremlinClient.ts", "./src/Explorer/Graph/GraphExplorerComponent/__mocks__/GremlinClient.ts",
"./src/Explorer/Graph/GraphExplorerComponent/ArraysByKeyCache.ts",
"./src/Explorer/Graph/GraphExplorerComponent/EdgeInfoCache.ts", "./src/Explorer/Graph/GraphExplorerComponent/EdgeInfoCache.ts",
"./src/Explorer/Graph/GraphExplorerComponent/GraphData.ts", "./src/Explorer/Graph/GraphExplorerComponent/GraphData.ts",
"./src/Explorer/Notebook/NotebookComponent/__mocks__/rx-jupyter.ts", "./src/Explorer/Notebook/NotebookComponent/__mocks__/rx-jupyter.ts",