Add cache timeout
This commit is contained in:
parent
823768bbc9
commit
576fd8ff40
5 changed files with 30 additions and 1 deletions
|
@ -42,6 +42,10 @@ export default class LayoutConfig {
|
||||||
public readonly enableGeolocation: boolean;
|
public readonly enableGeolocation: boolean;
|
||||||
public readonly enableBackgroundLayerSelection: boolean;
|
public readonly enableBackgroundLayerSelection: boolean;
|
||||||
public readonly customCss?: string;
|
public readonly customCss?: string;
|
||||||
|
/*
|
||||||
|
How long is the cache valid, in seconds?
|
||||||
|
*/
|
||||||
|
public readonly cacheTimeout?: number;
|
||||||
private readonly _official: boolean;
|
private readonly _official: boolean;
|
||||||
|
|
||||||
constructor(json: LayoutConfigJson, official = true, context?: string) {
|
constructor(json: LayoutConfigJson, official = true, context?: string) {
|
||||||
|
@ -167,6 +171,7 @@ export default class LayoutConfig {
|
||||||
this.enableAddNewPoints = json.enableAddNewPoints ?? true;
|
this.enableAddNewPoints = json.enableAddNewPoints ?? true;
|
||||||
this.enableBackgroundLayerSelection = json.enableBackgroundLayerSelection ?? true;
|
this.enableBackgroundLayerSelection = json.enableBackgroundLayerSelection ?? true;
|
||||||
this.customCss = json.customCss;
|
this.customCss = json.customCss;
|
||||||
|
this.cacheTimeout = json.cacheTimout ?? (60 * 24 * 60 * 60)
|
||||||
}
|
}
|
||||||
|
|
||||||
public CustomCodeSnippets(): string[] {
|
public CustomCodeSnippets(): string[] {
|
||||||
|
|
|
@ -118,6 +118,25 @@ export interface LayoutConfigJson {
|
||||||
* The id of the default background. BY default: vanilla OSM
|
* The id of the default background. BY default: vanilla OSM
|
||||||
*/
|
*/
|
||||||
defaultBackgroundId?: string;
|
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;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -15,6 +15,10 @@ export default class LocalStorageSaver implements FeatureSource {
|
||||||
this.features = source.features;
|
this.features = source.features;
|
||||||
|
|
||||||
this.features.addCallbackAndRun(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) {
|
if (features === undefined) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,7 @@ import { Utils } from "../Utils";
|
||||||
|
|
||||||
export default class Constants {
|
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
|
// The user journey states thresholds when a new feature gets unlocked
|
||||||
public static userJourney = {
|
public static userJourney = {
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
"startLon": 3.231,
|
"startLon": 3.231,
|
||||||
"startZoom": 14,
|
"startZoom": 14,
|
||||||
"widenFactor": 0.05,
|
"widenFactor": 0.05,
|
||||||
|
"cacheTimeout": 3600,
|
||||||
"socialImage": "",
|
"socialImage": "",
|
||||||
"layers": [
|
"layers": [
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue