Work on cache handling
This commit is contained in:
@@ -54,6 +54,7 @@ let ver_idb = '2025-04-18_1100'; // Not used
|
|||||||
const ae_app_local_data_defaults: key_val = {
|
const ae_app_local_data_defaults: key_val = {
|
||||||
last_page_reload: null,
|
last_page_reload: null,
|
||||||
// last_idb_reload: null,
|
// last_idb_reload: null,
|
||||||
|
last_cache_refresh: null,
|
||||||
ver: ver, // ver, // '2025-04-18_1100',
|
ver: ver, // ver, // '2025-04-18_1100',
|
||||||
ver_idb: ver_idb, // '2025-04-18_1100',
|
ver_idb: ver_idb, // '2025-04-18_1100',
|
||||||
name: 'Aether - App Hub (SvelteKit 2.x Svelte 4.x)',
|
name: 'Aether - App Hub (SvelteKit 2.x Svelte 4.x)',
|
||||||
|
|||||||
@@ -75,6 +75,30 @@ if (log_lvl > 1) {
|
|||||||
console.log(`ae_root +layout.svelte data:`, data);
|
console.log(`ae_root +layout.svelte data:`, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Get the current datetime
|
||||||
|
let early_check_current_datetime = new Date(); // Date.now()
|
||||||
|
|
||||||
|
// Check if the iframe parameter is set to true
|
||||||
|
// let early_check_iframe = data.url.searchParams.get('iframe');
|
||||||
|
|
||||||
|
|
||||||
|
// if (
|
||||||
|
// browser
|
||||||
|
// && early_check_iframe == 'true'
|
||||||
|
// && (
|
||||||
|
// !$ae_loc?.last_cache_refresh
|
||||||
|
// || (
|
||||||
|
// $ae_loc?.last_cache_refresh
|
||||||
|
// && (Date.now() - $ae_loc?.last_cache_refresh) > 1 * 60 * 1000
|
||||||
|
// )
|
||||||
|
// )
|
||||||
|
// ) {
|
||||||
|
// console.log(`TEST: Use iframe layout! last_cache_refresh:`, $ae_loc?.last_cache_refresh);
|
||||||
|
|
||||||
|
// // localStorage.clear();
|
||||||
|
// window.location.reload();
|
||||||
|
// }
|
||||||
|
|
||||||
let trigger_clear_access: null|boolean = $state(null);
|
let trigger_clear_access: null|boolean = $state(null);
|
||||||
|
|
||||||
// let account_id = localStorage.getItem('ae_account_id');
|
// let account_id = localStorage.getItem('ae_account_id');
|
||||||
@@ -187,11 +211,11 @@ if (log_lvl > 1) {
|
|||||||
// }
|
// }
|
||||||
|
|
||||||
// localStorage caches - Check if the last refresh timestamp for $ae_loc.last_refresh is no more than 48 hours ago.
|
// localStorage caches - Check if the last refresh timestamp for $ae_loc.last_refresh is no more than 48 hours ago.
|
||||||
let default_refresh_time = 48 * 60 * 60 * 1000; // 48 hours or 2880 minutes? 48 * 60 *
|
let default_refresh_time = 4 * 60 * 60 * 1000; // 48 hours or 2880 minutes? 48 * 60 *
|
||||||
let trusted_refresh_time = 168 * 60 * 60 * 1000; // 1 week or 10080 minutes?
|
let trusted_refresh_time = 168 * 60 * 60 * 1000; // 1 week or 10080 minutes?
|
||||||
|
|
||||||
// IDB caches - Check if the last refresh timestamp for $ae_loc.last_cache_refresh is no more than 15 minutes ago.
|
// IDB caches - Check if the last refresh timestamp for $ae_loc.last_cache_refresh is no more than 15 minutes ago.
|
||||||
let default_idb_refresh_time = 120 * 60 * 1000; // 15 minutes?
|
let default_idb_refresh_time = 2 * 60 * 60 * 1000; // 15 minutes?
|
||||||
let trusted_idb_refresh_time = 4 * 60 * 60 * 1000; // 4 hours or 120 minutes?
|
let trusted_idb_refresh_time = 4 * 60 * 60 * 1000; // 4 hours or 120 minutes?
|
||||||
|
|
||||||
// There should almost always be an event_id set.
|
// There should almost always be an event_id set.
|
||||||
@@ -361,9 +385,9 @@ if (browser) {
|
|||||||
// }
|
// }
|
||||||
|
|
||||||
if (!$ae_loc?.last_cache_refresh) {
|
if (!$ae_loc?.last_cache_refresh) {
|
||||||
if (log_lvl) {
|
// if (log_lvl) {
|
||||||
console.log(`Last reload not found. Need to set!`);
|
console.log(`Last reload not found. Need to set!`);
|
||||||
}
|
// }
|
||||||
|
|
||||||
$ae_loc.last_cache_refresh = Date.now();
|
$ae_loc.last_cache_refresh = Date.now();
|
||||||
|
|
||||||
@@ -374,6 +398,10 @@ if (browser) {
|
|||||||
indexedDB.deleteDatabase('ae_journals_db');
|
indexedDB.deleteDatabase('ae_journals_db');
|
||||||
indexedDB.deleteDatabase('ae_notes_db');
|
indexedDB.deleteDatabase('ae_notes_db');
|
||||||
indexedDB.deleteDatabase('ae_posts_db');
|
indexedDB.deleteDatabase('ae_posts_db');
|
||||||
|
|
||||||
|
localStorage.clear();
|
||||||
|
|
||||||
|
window.location.reload();
|
||||||
} else if ($ae_loc?.last_cache_refresh && $ae_loc?.trusted_access && (Date.now() - $ae_loc?.last_cache_refresh) > trusted_refresh_time) {
|
} else if ($ae_loc?.last_cache_refresh && $ae_loc?.trusted_access && (Date.now() - $ae_loc?.last_cache_refresh) > trusted_refresh_time) {
|
||||||
if (log_lvl) {
|
if (log_lvl) {
|
||||||
console.log(`Last (trusted) reload too old: ${$ae_loc.last_cache_refresh}`);
|
console.log(`Last (trusted) reload too old: ${$ae_loc.last_cache_refresh}`);
|
||||||
@@ -628,6 +656,8 @@ $effect(() => {
|
|||||||
localStorage.clear();
|
localStorage.clear();
|
||||||
sessionStorage.clear();
|
sessionStorage.clear();
|
||||||
|
|
||||||
|
confirm('Local and Session Storage cleared. The page should now refresh on its own.');
|
||||||
|
|
||||||
window.location.reload();
|
window.location.reload();
|
||||||
}}
|
}}
|
||||||
ondblclick={() => {
|
ondblclick={() => {
|
||||||
@@ -642,7 +672,8 @@ $effect(() => {
|
|||||||
localStorage.clear();
|
localStorage.clear();
|
||||||
sessionStorage.clear();
|
sessionStorage.clear();
|
||||||
|
|
||||||
alert('Local and Session Storage cleared. The page should now refresh on its own.');
|
confirm('Local and Session Storage cleared. The page should now refresh on its own.');
|
||||||
|
|
||||||
// window.location.reload({forceGet: true});
|
// window.location.reload({forceGet: true});
|
||||||
// window.location.reload(true);
|
// window.location.reload(true);
|
||||||
window.location.reload();
|
window.location.reload();
|
||||||
@@ -673,31 +704,41 @@ $effect(() => {
|
|||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
onclick={() => {
|
onclick={() => {
|
||||||
|
console.log('Reloading page...');
|
||||||
// Clear the localStorage and sessionStorage, then reload the page.
|
// Clear the localStorage and sessionStorage, then reload the page.
|
||||||
indexedDB.deleteDatabase('ae_core_db');
|
// indexedDB.deleteDatabase('ae_core_db');
|
||||||
indexedDB.deleteDatabase('ae_archives_db');
|
// indexedDB.deleteDatabase('ae_archives_db');
|
||||||
indexedDB.deleteDatabase('ae_events_db');
|
// indexedDB.deleteDatabase('ae_events_db');
|
||||||
indexedDB.deleteDatabase('ae_journals_db');
|
// indexedDB.deleteDatabase('ae_journals_db');
|
||||||
indexedDB.deleteDatabase('ae_posts_db');
|
// indexedDB.deleteDatabase('ae_posts_db');
|
||||||
|
|
||||||
|
// confirm('Local and Session Storage cleared. The page should now refresh on its own.');
|
||||||
|
|
||||||
|
// Clear localStorage and sessionStorage
|
||||||
|
localStorage.clear();
|
||||||
|
// sessionStorage.clear();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
window.location.reload();
|
window.location.reload();
|
||||||
}}
|
}}
|
||||||
ondblclick={() => {
|
ondblclick={() => {
|
||||||
// Double click to clear all databases and reload the page.
|
// // Double click to clear all databases and reload the page.
|
||||||
indexedDB.deleteDatabase('ae_core_db');
|
// indexedDB.deleteDatabase('ae_core_db');
|
||||||
indexedDB.deleteDatabase('ae_archives_db');
|
// indexedDB.deleteDatabase('ae_archives_db');
|
||||||
indexedDB.deleteDatabase('ae_events_db');
|
// indexedDB.deleteDatabase('ae_events_db');
|
||||||
indexedDB.deleteDatabase('ae_journals_db');
|
// indexedDB.deleteDatabase('ae_journals_db');
|
||||||
indexedDB.deleteDatabase('ae_posts_db');
|
// indexedDB.deleteDatabase('ae_posts_db');
|
||||||
|
|
||||||
// Clear localStorage and sessionStorage
|
// // Clear localStorage and sessionStorage
|
||||||
localStorage.clear();
|
// localStorage.clear();
|
||||||
sessionStorage.clear();
|
// sessionStorage.clear();
|
||||||
|
|
||||||
alert('Local and Session Storage cleared. The page should now refresh on its own.');
|
// confirm('DOUBLE CLICk: Local and Session Storage cleared. The page should now refresh on its own.');
|
||||||
// window.location.reload({forceGet: true});
|
|
||||||
// window.location.reload(true);
|
// // window.location.reload({forceGet: true});
|
||||||
window.location.reload();
|
// // window.location.reload(true);
|
||||||
|
// window.location.reload();
|
||||||
}}
|
}}
|
||||||
class="btn btn-sm m-1 variant-ghost-surface hover:variant-ghost-warning hover:variant-outline-warning text-error-600 hover:text-error-900 transition-all"
|
class="btn btn-sm m-1 variant-ghost-surface hover:variant-ghost-warning hover:variant-outline-warning text-error-600 hover:text-error-900 transition-all"
|
||||||
title="Reload and clear the page cache"
|
title="Reload and clear the page cache"
|
||||||
@@ -966,7 +1007,7 @@ max-w-max -->
|
|||||||
<Element_access_type
|
<Element_access_type
|
||||||
show_passcode_input={$ae_loc.app_cfg.show_element__passcode_input}
|
show_passcode_input={$ae_loc.app_cfg.show_element__passcode_input}
|
||||||
trigger_clear_access={trigger_clear_access}
|
trigger_clear_access={trigger_clear_access}
|
||||||
hidden={$ae_loc.iframe && !$ae_loc.trusted_access}
|
hidden={$ae_loc.iframe && !$ae_loc.trusted_access && !$ae_loc?.app_cfg?.show_element__menu}
|
||||||
/>
|
/>
|
||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user