feat(frontend): add dataset cache clearing utilities and integration (#35264)

Co-authored-by: Claude <noreply@anthropic.com>
Co-authored-by: Geidō <60598000+geido@users.noreply.github.com>
This commit is contained in:
Mehmet Salih Yavuz
2025-11-12 17:23:37 +03:00
committed by GitHub
co-authored by Claude Geidō
parent 9fbfcf0ccd
commit 0b535b792e
6 changed files with 303 additions and 4 deletions
@@ -27,3 +27,59 @@ export const cachedSupersetGet = cacheWrapper(
supersetGetCache,
({ endpoint }) => endpoint || '',
);
/**
* Clear cached responses for dataset-related endpoints
* @param datasetId - The ID of the dataset to clear from cache
*/
export function clearDatasetCache(datasetId: number | string): void {
if (datasetId === null || datasetId === undefined || datasetId === '') return;
const datasetIdStr = String(datasetId);
supersetGetCache.forEach((_value, key) => {
// Match exact dataset ID patterns:
// - /api/v1/dataset/123 (exact match or end of URL)
// - /api/v1/dataset/123/ (with trailing slash)
// - /api/v1/dataset/123? (with query params)
const patterns = [
`/api/v1/dataset/${datasetIdStr}`,
`/api/v1/dataset/${datasetIdStr}/`,
`/api/v1/dataset/${datasetIdStr}?`,
];
for (const pattern of patterns) {
if (key.includes(pattern)) {
// Additional check to ensure we don't match longer IDs
const afterPattern = key.substring(
key.indexOf(pattern) + pattern.length,
);
// If pattern ends with slash or query, it's already precise
if (pattern.endsWith('/') || pattern.endsWith('?')) {
supersetGetCache.delete(key);
break;
}
// For the base pattern, ensure nothing follows or only valid separators
if (
afterPattern === '' ||
afterPattern.startsWith('/') ||
afterPattern.startsWith('?')
) {
supersetGetCache.delete(key);
break;
}
}
}
});
}
/**
* Clear all cached dataset responses
*/
export function clearAllDatasetCache(): void {
supersetGetCache.forEach((_value, key) => {
if (key.includes('/api/v1/dataset/')) {
supersetGetCache.delete(key);
}
});
}