Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into nathan/sdk-submodule
Browse files Browse the repository at this point in the history
  • Loading branch information
NathanFlurry committed Oct 26, 2023
2 parents 5fb7d46 + f517698 commit 2b4fba0
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/utils/cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ interface CacheWrapper<T> {
data: T;

ts: number;
// version: string;
version: string;
}

export interface LocalStorageChange {
Expand Down Expand Up @@ -144,7 +144,11 @@ export async function readCache<T>(keyPath: string[]): Promise<T> {
let wrapper = data;

// Cache expired or outdated (used to use blobs)
if (wrapper instanceof Blob || Date.now() - (wrapper.ts as number) >= CACHE_LIFETIME) {
if (
wrapper instanceof Blob ||
Date.now() - wrapper.ts >= CACHE_LIFETIME ||
wrapper.version != config.GIT_COMMIT
) {
logging.debug('Cache expired', key);
deleteIDB(db, key);

Expand All @@ -165,7 +169,8 @@ export async function writeCache<T>(keyPath: string[], payload: T) {
// Add timestamp and version properties
let cacheWrapper: CacheWrapper<T> = {
data: payload,
ts: Date.now()
ts: Date.now(),
version: config.GIT_COMMIT
};

// Gracefully get DB
Expand Down

0 comments on commit 2b4fba0

Please sign in to comment.