mirror of
https://gitlab.com/openstapps/openstapps.git
synced 2026-01-20 08:33:11 +00:00
feat: Ionic v6 breadcrumbs in catalog module
This commit is contained in:
@@ -30,6 +30,7 @@ import {
|
||||
SCSaveableThing,
|
||||
SCFeedbackRequest,
|
||||
SCFeedbackResponse,
|
||||
SCUuid,
|
||||
} from '@openstapps/core';
|
||||
import {environment} from '../../../environments/environment';
|
||||
import {StorageProvider} from '../storage/storage.provider';
|
||||
@@ -41,6 +42,11 @@ export enum DataScope {
|
||||
Remote = 'remote',
|
||||
}
|
||||
|
||||
interface CacheItem<T> {
|
||||
data: Promise<T>;
|
||||
timestamp: number;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generated class for the DataProvider provider.
|
||||
*
|
||||
@@ -70,6 +76,10 @@ export class DataProvider {
|
||||
*/
|
||||
private _storagePrefix = 'stapps.data';
|
||||
|
||||
readonly cache: Record<SCUuid, CacheItem<SCThings> | undefined> = {};
|
||||
|
||||
private maxCacheAge = 3600;
|
||||
|
||||
/**
|
||||
* Version of the app (used for the header in communication with the backend)
|
||||
*/
|
||||
@@ -229,7 +239,17 @@ export class DataProvider {
|
||||
return this.storageProvider.get<SCSaveableThing>(this.getDataKey(uid));
|
||||
}
|
||||
if (scope === DataScope.Remote) {
|
||||
return this.client.getThing(uid);
|
||||
const timestamp = Date.now();
|
||||
const cacheItem = this.cache[uid];
|
||||
if (cacheItem && timestamp - cacheItem.timestamp < this.maxCacheAge) {
|
||||
return cacheItem.data;
|
||||
}
|
||||
const item = this.client.getThing(uid);
|
||||
this.cache[uid] = {
|
||||
data: item,
|
||||
timestamp: timestamp,
|
||||
};
|
||||
return item;
|
||||
}
|
||||
const map: Map<DataScope, SCThings | SCSaveableThing> = new Map();
|
||||
map.set(DataScope.Local, await this.get(uid, DataScope.Local));
|
||||
|
||||
Reference in New Issue
Block a user