The open and composable observability and data visualization platform. Visualize metrics, logs, and traces from multiple sources like Prometheus, Loki, Elasticsearch, InfluxDB, Postgres and many more.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
grafana/public/app/features/plugins/pluginCacheBuster.ts

48 lines
1.1 KiB

import { clearPluginSettingsCache } from './pluginSettings';
const cache: Record<string, string> = {};
const initializedAt: number = Date.now();
type CacheablePlugin = {
path: string;
version: string;
};
export function registerPluginInCache({ path, version }: CacheablePlugin): void {
if (!cache[path]) {
cache[path] = encodeURI(version);
}
}
export function invalidatePluginInCache(pluginId: string): void {
const path = `plugins/${pluginId}/module`;
if (cache[path]) {
delete cache[path];
}
clearPluginSettingsCache(pluginId);
}
export function locateWithCache(load: { address: string }, defaultBust = initializedAt): string {
const { address } = load;
const path = extractPath(address);
if (!path) {
return `${address}?_cache=${defaultBust}`;
}
const version = cache[path];
const bust = version || defaultBust;
return `${address}?_cache=${bust}`;
}
function extractPath(address: string): string | undefined {
const match = /\/public\/(plugins\/.+\/module)\.js/i.exec(address);
if (!match) {
return;
}
const [_, path] = match;
if (!path) {
return;
}
return path;
}