Add cache timeout

This commit is contained in:
pietervdvn 2021-04-17 15:42:22 +02:00
parent 823768bbc9
commit 576fd8ff40
5 changed files with 30 additions and 1 deletions

View file

@ -42,6 +42,10 @@ export default class LayoutConfig {
public readonly enableGeolocation: boolean;
public readonly enableBackgroundLayerSelection: boolean;
public readonly customCss?: string;
/*
How long is the cache valid, in seconds?
*/
public readonly cacheTimeout?: number;
private readonly _official: boolean;
constructor(json: LayoutConfigJson, official = true, context?: string) {
@ -167,6 +171,7 @@ export default class LayoutConfig {
this.enableAddNewPoints = json.enableAddNewPoints ?? true;
this.enableBackgroundLayerSelection = json.enableBackgroundLayerSelection ?? true;
this.customCss = json.customCss;
this.cacheTimeout = json.cacheTimout ?? (60 * 24 * 60 * 60)
}
public CustomCodeSnippets(): string[] {

View file

@ -119,6 +119,25 @@ export interface LayoutConfigJson {
*/
defaultBackgroundId?: string;
/**
* The number of seconds that a feature is allowed to stay in the cache.
* The caching flow is as following:
*
* 1. The application is opened the first time
* 2. An overpass query is run
* 3. The result is saved to local storage
*
* On the next opening:
*
* 1. The application is opened
* 2. Data is loaded from cache and displayed
* 3. An overpass query is run
* 4. All data (both from overpass ánd local storage) are saved again to local storage (except when to old)
*
* Default value: 60 days
*/
cacheTimout?: number;
/**
* The layers to display.

View file

@ -15,6 +15,10 @@ export default class LocalStorageSaver implements FeatureSource {
this.features = source.features;
this.features.addCallbackAndRun(features => {
const now = new Date().getTime()
features = features.filter(f => layout.data.cacheTimeout > Math.abs(now - f.freshness.getTime())/1000)
if (features === undefined) {
return;
}

View file

@ -2,7 +2,7 @@ import { Utils } from "../Utils";
export default class Constants {
public static vNumber = "0.6.8b";
public static vNumber = "0.6.8c";
// The user journey states thresholds when a new feature gets unlocked
public static userJourney = {

View file

@ -19,6 +19,7 @@
"startLon": 3.231,
"startZoom": 14,
"widenFactor": 0.05,
"cacheTimeout": 3600,
"socialImage": "",
"layers": [
{