Optimised cach usage, and enforced maker checker
This commit is contained in:
@@ -293,7 +293,6 @@ export function DashboardPage() {
|
||||
queryKey: ['partner-applicant-data', applicantUserId],
|
||||
queryFn: () => getApplicantData(applicantUserId),
|
||||
enabled: Boolean(applicantUserId),
|
||||
staleTime: 30_000,
|
||||
});
|
||||
|
||||
// Extract all unique projects, contracts, awards, and organisations from ApplicantData[]
|
||||
@@ -426,7 +425,6 @@ export function DashboardPage() {
|
||||
return Object.fromEntries(results);
|
||||
},
|
||||
enabled: partnerSummary.projectEntries.length > 0,
|
||||
staleTime: 30_000,
|
||||
});
|
||||
|
||||
// Combine into EnrichedPartnerProject[]
|
||||
|
||||
@@ -113,7 +113,6 @@ export function useInAppNotifications() {
|
||||
return list || [];
|
||||
},
|
||||
refetchInterval: 30000,
|
||||
staleTime: 10000,
|
||||
});
|
||||
|
||||
const inAppNotifications = useMemo(() => {
|
||||
|
||||
@@ -4,15 +4,38 @@ import { bumpMutationEpoch } from '../services/httpClient';
|
||||
export const queryClient = new QueryClient({
|
||||
defaultOptions: {
|
||||
queries: {
|
||||
staleTime: 1000 * 60 * 2, // 2 minutes fresh in memory
|
||||
gcTime: 1000 * 60 * 10, // 10 minutes cache retention
|
||||
refetchOnWindowFocus: false,
|
||||
refetchOnReconnect: true,
|
||||
// Remove caching from all pages: zero stale time and zero cache retention
|
||||
// Whenever a component needs data, it must call its corresponding endpoint(s)
|
||||
staleTime: 0,
|
||||
gcTime: 0,
|
||||
refetchOnMount: 'always',
|
||||
refetchOnWindowFocus: 'always',
|
||||
refetchOnReconnect: 'always',
|
||||
retry: 1,
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
// Retain caching ONLY for sync status, auth token, roles and grants
|
||||
const RETAINED_CACHE_OPTIONS = {
|
||||
staleTime: 5 * 60 * 1000,
|
||||
gcTime: 10 * 60 * 1000,
|
||||
refetchOnMount: false,
|
||||
refetchOnWindowFocus: false,
|
||||
};
|
||||
|
||||
queryClient.setQueryDefaults(['roles'], RETAINED_CACHE_OPTIONS);
|
||||
queryClient.setQueryDefaults(['system-roles'], RETAINED_CACHE_OPTIONS);
|
||||
queryClient.setQueryDefaults(['role-claims'], RETAINED_CACHE_OPTIONS);
|
||||
queryClient.setQueryDefaults(['user-roles'], RETAINED_CACHE_OPTIONS);
|
||||
queryClient.setQueryDefaults(['user-claims'], RETAINED_CACHE_OPTIONS);
|
||||
queryClient.setQueryDefaults(['grants'], RETAINED_CACHE_OPTIONS);
|
||||
queryClient.setQueryDefaults(['user-grants'], RETAINED_CACHE_OPTIONS);
|
||||
queryClient.setQueryDefaults(['user-sync'], RETAINED_CACHE_OPTIONS);
|
||||
queryClient.setQueryDefaults(['sync-status'], RETAINED_CACHE_OPTIONS);
|
||||
queryClient.setQueryDefaults(['auth'], RETAINED_CACHE_OPTIONS);
|
||||
queryClient.setQueryDefaults(['auth-token'], RETAINED_CACHE_OPTIONS);
|
||||
|
||||
/**
|
||||
* Invalidates queries while simultaneously bumping the mutation epoch.
|
||||
*/
|
||||
|
||||
@@ -39,6 +39,8 @@ export const apiClient = axios.create({
|
||||
headers: {
|
||||
'Content-Type': 'application/json; version=1',
|
||||
Accept: 'application/json; version=1',
|
||||
'Cache-Control': 'no-cache, no-store, must-revalidate',
|
||||
Pragma: 'no-cache',
|
||||
},
|
||||
timeout: 15000,
|
||||
});
|
||||
@@ -58,31 +60,16 @@ apiClient.interceptors.request.use(
|
||||
config.url?.includes('amazonaws.com') ||
|
||||
config.url?.includes('garage');
|
||||
|
||||
// Always attach freshness timestamp and mutation epoch to internal GET requests
|
||||
// to guarantee zero stale data, bypass browser HTTP caches, and prevent stale OutputCache hits
|
||||
if (config.method?.toUpperCase() === 'GET' && !isExternal) {
|
||||
const headers = config.headers || {};
|
||||
const hasNoCacheHeader =
|
||||
headers['Cache-Control'] === 'no-cache' ||
|
||||
headers['cache-control'] === 'no-cache' ||
|
||||
headers['Pragma'] === 'no-cache';
|
||||
|
||||
if (hasNoCacheHeader) {
|
||||
if (config.params instanceof URLSearchParams) {
|
||||
config.params.set('_t', String(Date.now()));
|
||||
} else {
|
||||
config.params = config.params || {};
|
||||
config.params._t = Date.now();
|
||||
}
|
||||
if (config.params instanceof URLSearchParams) {
|
||||
config.params.set('_t', String(Date.now()));
|
||||
config.params.set('_v', String(getMutationEpoch()));
|
||||
} else {
|
||||
if (config.params instanceof URLSearchParams) {
|
||||
if (!config.params.has('_v') && !config.params.has('_t')) {
|
||||
config.params.set('_v', String(getMutationEpoch()));
|
||||
}
|
||||
} else {
|
||||
config.params = config.params || {};
|
||||
if (!config.params._v && !config.params._t) {
|
||||
config.params._v = getMutationEpoch();
|
||||
}
|
||||
}
|
||||
config.params = config.params || {};
|
||||
config.params._t = Date.now();
|
||||
config.params._v = getMutationEpoch();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user