in src/graph/Graph.ts [1412:1576]
public uncache(
keepIds: string[],
keepCellIds: string[],
keepSequenceId?: string)
: void {
const idsInUse: { [id: string]: boolean; } = {};
this._addNewKeys(idsInUse, this._cachingFull$);
this._addNewKeys(idsInUse, this._cachingFill$);
this._addNewKeys(idsInUse, this._cachingSpatialArea$);
this._addNewKeys(idsInUse, this._requiredNodeTiles);
this._addNewKeys(idsInUse, this._requiredSpatialArea);
for (const key of keepIds) {
if (key in idsInUse) { continue; }
idsInUse[key] = true;
}
const tileThreshold = this._tileThreshold;
const calculator = this._graphCalculator;
const geometry = this._api.data.geometry;
const keepCells = new Set<string>(keepCellIds);
for (let id in idsInUse) {
if (!idsInUse.hasOwnProperty(id)) { continue; }
const node = this._nodes[id];
const [sw, ne] = calculator
.boundingBoxCorners(
node.lngLat,
tileThreshold,
);
const nodeCellIds = geometry.bboxToCellIds(sw, ne);
for (const nodeCellId of nodeCellIds) {
if (!keepCells.has(nodeCellId)) {
keepCells.add(nodeCellId);
}
}
}
const potentialCells: [string, TileAccess][] = [];
for (let cellId in this._cachedTiles) {
if (!this._cachedTiles.hasOwnProperty(cellId) ||
keepCells.has(cellId)) {
continue;
}
potentialCells.push([cellId, this._cachedTiles[cellId]]);
}
const uncacheCells = potentialCells
.sort(
(h1: [string, TileAccess], h2: [string, TileAccess]): number => {
return h2[1].accessed - h1[1].accessed;
})
.slice(this._configuration.maxUnusedTiles)
.map(
(h: [string, TileAccess]): string => {
return h[0];
});
for (let uncacheCell of uncacheCells) {
this._uncacheTile(uncacheCell, keepSequenceId);
}
const potentialPreStored: [NodeAccess, string][] = [];
const nonCachedPreStored: [string, string][] = [];
for (let cellId in this._preStored) {
if (!this._preStored.hasOwnProperty(cellId) ||
cellId in this._cachingTiles$) {
continue;
}
const prestoredNodes = this._preStored[cellId];
for (let id in prestoredNodes) {
if (!prestoredNodes.hasOwnProperty(id) || id in idsInUse) {
continue;
}
if (prestoredNodes[id].sequenceId === keepSequenceId) {
continue;
}
if (id in this._cachedNodes) {
potentialPreStored.push([this._cachedNodes[id], cellId]);
} else {
nonCachedPreStored.push([id, cellId]);
}
}
}
const uncachePreStored = potentialPreStored
.sort(
([na1]: [NodeAccess, string], [na2]: [NodeAccess, string]): number => {
return na2.accessed - na1.accessed;
})
.slice(this._configuration.maxUnusedPreStoredImages)
.map(
([na, h]: [NodeAccess, string]): [string, string] => {
return [na.node.id, h];
});
this._uncachePreStored(nonCachedPreStored);
this._uncachePreStored(uncachePreStored);
const potentialNodes: NodeAccess[] = [];
for (let id in this._cachedNodes) {
if (!this._cachedNodes.hasOwnProperty(id) || id in idsInUse) {
continue;
}
potentialNodes.push(this._cachedNodes[id]);
}
const uncacheNodes = potentialNodes
.sort(
(n1: NodeAccess, n2: NodeAccess): number => {
return n2.accessed - n1.accessed;
})
.slice(this._configuration.maxUnusedImages);
for (const nodeAccess of uncacheNodes) {
nodeAccess.node.uncache();
const id = nodeAccess.node.id;
delete this._cachedNodes[id];
if (id in this._cachedNodeTiles) {
delete this._cachedNodeTiles[id];
}
if (id in this._cachedSpatialEdges) {
delete this._cachedSpatialEdges[id];
}
}
const potentialSequences: SequenceAccess[] = [];
for (let sequenceId in this._sequences) {
if (!this._sequences.hasOwnProperty(sequenceId) ||
sequenceId in this._cachingSequences$ ||
sequenceId === keepSequenceId) {
continue;
}
potentialSequences.push(this._sequences[sequenceId]);
}
const uncacheSequences = potentialSequences
.sort(
(s1: SequenceAccess, s2: SequenceAccess): number => {
return s2.accessed - s1.accessed;
})
.slice(this._configuration.maxSequences);
for (const sequenceAccess of uncacheSequences) {
const sequenceId = sequenceAccess.sequence.id;
delete this._sequences[sequenceId];
if (sequenceId in this._cachedSequenceNodes) {
delete this._cachedSequenceNodes[sequenceId];
}
sequenceAccess.sequence.dispose();
}
}