mirror of
https://github.com/apache/superset.git
synced 2026-08-12 11:11:01 +00:00
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:
co-authored by
Claude
Geidō
parent
9fbfcf0ccd
commit
0b535b792e
@@ -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);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user