add ArraysByKeyCache.ts (#366)
* 'add ArraysByKeyCache' * "minor change"
This commit is contained in:
parent
6627172a52
commit
2d98c5d269
|
@ -11,7 +11,9 @@ export class ArraysByKeyCache<T> {
|
|||
|
||||
public constructor(maxNbElements: number) {
|
||||
this.maxNbElements = maxNbElements;
|
||||
this.clear();
|
||||
this.keyQueue = [];
|
||||
this.cache = {};
|
||||
this.totalElements = 0;
|
||||
}
|
||||
|
||||
public clear(): void {
|
||||
|
@ -58,7 +60,7 @@ export class ArraysByKeyCache<T> {
|
|||
* @param startIndex
|
||||
* @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)) {
|
||||
return null;
|
||||
}
|
||||
|
@ -77,9 +79,11 @@ export class ArraysByKeyCache<T> {
|
|||
private reduceCacheSize(): void {
|
||||
// remove an key and its array
|
||||
const oldKey = this.keyQueue.shift();
|
||||
if (oldKey) {
|
||||
this.totalElements -= this.cache[oldKey].length;
|
||||
delete this.cache[oldKey];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Bubble up this key as new.
|
||||
|
|
|
@ -47,6 +47,7 @@
|
|||
"./src/Explorer/Controls/InputTypeahead/InputTypeahead.ts",
|
||||
"./src/Explorer/Controls/SmartUi/InputUtils.ts",
|
||||
"./src/Explorer/Graph/GraphExplorerComponent/__mocks__/GremlinClient.ts",
|
||||
"./src/Explorer/Graph/GraphExplorerComponent/ArraysByKeyCache.ts",
|
||||
"./src/Explorer/Graph/GraphExplorerComponent/EdgeInfoCache.ts",
|
||||
"./src/Explorer/Graph/GraphExplorerComponent/GraphData.ts",
|
||||
"./src/Explorer/Notebook/NotebookComponent/__mocks__/rx-jupyter.ts",
|
||||
|
|
Loading…
Reference in New Issue