forked from MapComplete/MapComplete
Force cache clearing when a new point is added, fix #522
This commit is contained in:
parent
936cf1bf9f
commit
d1ecaf7527
3 changed files with 32 additions and 7 deletions
|
@ -4,6 +4,7 @@
|
|||
* Technically, more an Actor then a featuresource, but it fits more neatly this ay
|
||||
*/
|
||||
import {FeatureSourceForLayer} from "../FeatureSource";
|
||||
import {Tiles} from "../../../Models/TileRange";
|
||||
|
||||
export default class SaveTileToLocalStorageActor {
|
||||
public static readonly storageKey: string = "cached-features";
|
||||
|
@ -37,4 +38,21 @@ export default class SaveTileToLocalStorageActor {
|
|||
console.error("Could not mark tile ", key, "as visited")
|
||||
}
|
||||
}
|
||||
|
||||
public static poison(layers: string[], lon: number, lat: number) {
|
||||
for (let z = 0; z < 25; z++) {
|
||||
|
||||
const {x, y} = Tiles.embedded_tile(lat, lon, z)
|
||||
const tileId = Tiles.tile_index(z, x, y)
|
||||
|
||||
for (const layerId of layers) {
|
||||
|
||||
const key = `${SaveTileToLocalStorageActor.storageKey}-${layerId}-${tileId}`
|
||||
localStorage.removeItem(key + "-time");
|
||||
localStorage.removeItem(key + "-format")
|
||||
localStorage.removeItem(key)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -91,15 +91,23 @@ export default class FeaturePipeline {
|
|||
|
||||
const self = this
|
||||
const expiryInSeconds = Math.min(...state.layoutToUse.layers.map(l => l.maxAgeOfCache))
|
||||
this.oldestAllowedDate = new Date(new Date().getTime() - expiryInSeconds);
|
||||
for (const layer of state.layoutToUse.layers) {
|
||||
TiledFromLocalStorageSource.cleanCacheForLayer(layer)
|
||||
}
|
||||
this.oldestAllowedDate = new Date(new Date().getTime() - expiryInSeconds);
|
||||
this.osmSourceZoomLevel = state.osmApiTileSize.data;
|
||||
// milliseconds
|
||||
const useOsmApi = state.locationControl.map(l => l.zoom > (state.overpassMaxZoom.data ?? 12))
|
||||
this.relationTracker = new RelationsTracker()
|
||||
|
||||
state.changes.allChanges.addCallbackAndRun(allChanges => {
|
||||
allChanges.filter(ch => ch.id < 0)
|
||||
.map(ch => ch.changes)
|
||||
.filter(coor => coor["lat"] !== undefined && coor["lon"] !== undefined)
|
||||
.forEach(coor => {
|
||||
SaveTileToLocalStorageActor.poison(state.layoutToUse.layers.map(l => l.id), coor["lon"], coor["lat"])
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
this.sufficientlyZoomed = state.locationControl.map(location => {
|
||||
if (location?.zoom === undefined) {
|
||||
|
|
|
@ -47,7 +47,6 @@ export default class TiledFromLocalStorageSource implements TileHierarchy<Featur
|
|||
localStorage.removeItem(k)
|
||||
localStorage.removeItem(k+"-format")
|
||||
localStorage.removeItem(k+"-time")
|
||||
console.debug("Removed "+k+" from local storage: too old")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue