forked from chartdb/chartdb
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(AI exports): add cahching layer to SQL exports (chartdb#390)
* fix(AI exports): add cahching layer to SQL exports * remove logs --------- Co-authored-by: Guy Ben-Aharon <baguy3@gmail.com>
- Loading branch information
1 parent
959e540
commit e5dbbf2
Showing
3 changed files
with
56 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import type { DatabaseType } from '@/lib/domain/database-type'; | ||
import { sha256 } from '@/lib/utils'; | ||
|
||
export const getFromCache = (key: string): string | null => { | ||
try { | ||
return localStorage.getItem(`sql-export-${key}`); | ||
} catch (e) { | ||
console.warn('Failed to read from localStorage:', e); | ||
return null; | ||
} | ||
}; | ||
|
||
export const setInCache = (key: string, value: string): void => { | ||
try { | ||
localStorage.setItem(`sql-export-${key}`, value); | ||
} catch (e) { | ||
console.warn('Failed to write to localStorage:', e); | ||
} | ||
}; | ||
|
||
export const generateCacheKey = async ( | ||
databaseType: DatabaseType, | ||
sqlScript: string | ||
): Promise<string> => { | ||
const rawKey = `${databaseType}:${sqlScript}`; | ||
return await sha256(rawKey); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters