MCPcopy Index your code
hub / github.com/rx-angular/rx-angular / invalidate

Method invalidate

libs/isr/server/src/isr-handler.ts:50–138  ·  view source on GitHub ↗
(
    req: Request,
    res: Response,
    config?: InvalidateConfig,
  )

Source from the content-addressed store, hash-verified

48 }
49
50 async invalidate(
51 req: Request,
52 res: Response,
53 config?: InvalidateConfig,
54 ): Promise<Response> {
55 const { token, urlsToInvalidate } = extractDataFromBody(req);
56
57 if (token !== this.isrConfig.invalidateSecretToken) {
58 return res.json({
59 status: 'error',
60 message: 'Your secret token is wrong!!!',
61 });
62 }
63
64 if (!urlsToInvalidate || !urlsToInvalidate.length) {
65 return res.json({
66 status: 'error',
67 message: 'Please add `urlsToInvalidate` in the payload!',
68 });
69 }
70
71 const notInCache: string[] = [];
72 const urlWithErrors: Record<string, string[]> = {};
73
74 // Include all possible variants in the list of URLs to be invalidated including
75 // their modified request to regenerate the pages
76 const variantUrlsToInvalidate =
77 this.getVariantUrlsToInvalidate(urlsToInvalidate);
78
79 for (const variantUrl of variantUrlsToInvalidate) {
80 const { cacheKey, url, reqSimulator } = variantUrl;
81
82 // check if the url is in cache
83 const urlExists = await this.cache.has(cacheKey);
84
85 if (!urlExists) {
86 notInCache.push(cacheKey);
87 continue;
88 }
89 // override url of req with the one in parameters,
90 req.url = url;
91 try {
92 const result = await this.cacheGeneration.generateWithCacheKey(
93 reqSimulator(req),
94 res,
95 cacheKey,
96 config?.providers,
97 'generate',
98 );
99
100 if (result && result.errors?.length) {
101 urlWithErrors[cacheKey] = result.errors;
102 }
103 } catch (err) {
104 urlWithErrors[cacheKey] = err as string[];
105 }
106 }
107

Callers 1

appFunction · 0.95

Calls 6

extractDataFromBodyFunction · 0.85
generateWithCacheKeyMethod · 0.80
hasMethod · 0.45
filterMethod · 0.45
logMethod · 0.45

Tested by

no test coverage detected