mirror of
https://github.com/nikdoof/pocket-id.git
synced 2025-12-14 15:22:18 +00:00
fix: cache version information for 3 hours
This commit is contained in:
24
frontend/src/routes/settings/+layout.server.ts
Normal file
24
frontend/src/routes/settings/+layout.server.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
import AppConfigService from '$lib/services/app-config-service';
|
||||
import type { AppVersionInformation } from '$lib/types/application-configuration';
|
||||
import type { LayoutServerLoad } from './$types';
|
||||
|
||||
let versionInformation: AppVersionInformation;
|
||||
let versionInformationLastUpdated: number;
|
||||
|
||||
export const load: LayoutServerLoad = async () => {
|
||||
const appConfigService = new AppConfigService();
|
||||
|
||||
// Cache the version information for 3 hours
|
||||
const cacheExpired =
|
||||
versionInformationLastUpdated &&
|
||||
Date.now() - versionInformationLastUpdated > 1000 * 60 * 60 * 3;
|
||||
|
||||
if (!versionInformation || cacheExpired) {
|
||||
versionInformation = await appConfigService.getVersionInformation();
|
||||
versionInformationLastUpdated = Date.now();
|
||||
}
|
||||
|
||||
return {
|
||||
versionInformation
|
||||
};
|
||||
};
|
||||
@@ -1,11 +0,0 @@
|
||||
import AppConfigService from '$lib/services/app-config-service';
|
||||
import type { LayoutLoad } from './$types';
|
||||
|
||||
export const load: LayoutLoad = async () => {
|
||||
const appConfigService = new AppConfigService();
|
||||
|
||||
const versionInformation = await appConfigService.getVersionInformation();
|
||||
return {
|
||||
versionInformation
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user