forked from MapComplete/MapComplete
Invalidate cache if a point has been deleted or changed geometry. Fix #865; review cache retention times and disable cache for external geojson datasets, fix #1660
This commit is contained in:
parent
adaff94dbd
commit
a399260bf0
6 changed files with 68 additions and 39 deletions
|
@ -5,6 +5,8 @@ import { GeoOperations } from "../../GeoOperations"
|
|||
import FeaturePropertiesStore from "./FeaturePropertiesStore"
|
||||
import { UIEventSource } from "../../UIEventSource"
|
||||
import { Utils } from "../../../Utils"
|
||||
import { Tiles } from "../../../Models/TileRange"
|
||||
import { BBox } from "../../BBox"
|
||||
|
||||
class SingleTileSaver {
|
||||
private readonly _storage: UIEventSource<Feature[]>
|
||||
|
@ -54,6 +56,8 @@ class SingleTileSaver {
|
|||
* Also see the sibling class
|
||||
*/
|
||||
export default class SaveFeatureSourceToLocalStorage {
|
||||
public readonly storage: TileLocalStorage<Feature[]>
|
||||
private zoomlevel: number
|
||||
constructor(
|
||||
backend: string,
|
||||
layername: string,
|
||||
|
@ -62,7 +66,9 @@ export default class SaveFeatureSourceToLocalStorage {
|
|||
featureProperties: FeaturePropertiesStore,
|
||||
maxCacheAge: number
|
||||
) {
|
||||
this.zoomlevel = zoomlevel
|
||||
const storage = TileLocalStorage.construct<Feature[]>(backend, layername, maxCacheAge)
|
||||
this.storage = storage
|
||||
const singleTileSavers: Map<number, SingleTileSaver> = new Map<number, SingleTileSaver>()
|
||||
features.features.addCallbackAndRunD((features) => {
|
||||
const sliced = GeoOperations.slice(zoomlevel, features)
|
||||
|
@ -80,4 +86,12 @@ export default class SaveFeatureSourceToLocalStorage {
|
|||
})
|
||||
})
|
||||
}
|
||||
|
||||
public invalidateCacheAround(bbox: BBox) {
|
||||
const range = Tiles.tileRangeFrom(bbox, this.zoomlevel)
|
||||
Tiles.MapRange(range, (x, y) => {
|
||||
const index = Tiles.tile_index(this.zoomlevel, x, y)
|
||||
this.storage.invalidate(index)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue