-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrevalidate-feeds.ts
More file actions
62 lines (53 loc) · 2.24 KB
/
revalidate-feeds.ts
File metadata and controls
62 lines (53 loc) · 2.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import 'server-only';
import { revalidatePath, revalidateTag } from 'next/cache';
import { AVAILABLE_LOCALES } from '../../i18n/routing';
/**
* Revalidates the ISR cache for specific feed pages.
* Applies to all feed types (gtfs, gtfs_rt, gbfs) since we don't know the type from the id alone.
* Also revalidates localized paths and /map sub-routes.
*/
export function revalidateSpecificFeeds(feedIds: string[]): void {
const localPaths = AVAILABLE_LOCALES.filter((loc) => loc !== 'en');
const pathsToRevalidate: string[] = [];
feedIds.forEach((id) => {
revalidateTag(`feed-${id}`, 'max');
// The id will try to revalidate all feed types with that id, but that's necessary since we don't know the feed type here and it's not a big deal if we revalidate some non-existent pages
pathsToRevalidate.push(`/feeds/gtfs/${id}`);
pathsToRevalidate.push(`/feeds/gtfs_rt/${id}`);
pathsToRevalidate.push(`/feeds/gbfs/${id}`);
});
console.log('Revalidating paths:', pathsToRevalidate);
pathsToRevalidate.forEach((path) => {
revalidatePath(path);
revalidatePath(path + '/map');
localPaths.forEach((loc) => {
revalidatePath(`/${loc}${path}`);
revalidatePath(`/${loc}${path}/map`);
});
});
}
/** Clears cache for all feed pages (ISR-cached layout). */
export function revalidateAllFeeds(): void {
revalidateTag('guest-feeds', 'max');
revalidatePath('/[locale]/feeds/[feedDataType]/[feedId]', 'layout');
}
/** Clears cache for all GBFS feed pages (ISR-cached layout). */
export function revalidateAllGbfsFeeds(): void {
revalidateTag('feed-type-gbfs', 'max');
revalidatePath('/[locale]/feeds/gbfs/[feedId]', 'layout');
}
/** Clears cache for all GTFS feed pages (ISR-cached layout). */
export function revalidateAllGtfsFeeds(): void {
revalidateTag('feed-type-gtfs', 'max');
revalidatePath('/[locale]/feeds/gtfs/[feedId]', 'layout');
}
/** Clears cache for all GTFS-RT feed pages (ISR-cached layout). */
export function revalidateAllGtfsRtFeeds(): void {
revalidateTag('feed-type-gtfs_rt', 'max');
revalidatePath('/[locale]/feeds/gtfs_rt/[feedId]', 'layout');
}
/** Clears cache for the entire site. */
export function revalidateFullSite(): void {
revalidateTag('guest-feeds', 'max');
revalidatePath('/', 'layout');
}