mirror of
				https://github.com/chartdb/chartdb.git
				synced 2025-11-04 05:53:15 +00:00 
			
		
		
		
	* fix(AI exports): add cahching layer to SQL exports * remove logs --------- Co-authored-by: Guy Ben-Aharon <baguy3@gmail.com>
		
			
				
	
	
		
			28 lines
		
	
	
		
			772 B
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
			
		
		
	
	
			28 lines
		
	
	
		
			772 B
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
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);
 | 
						|
};
 |