-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add clientSDKKey as a tag on the config request so it can be invalida…
…ted from the client side
- Loading branch information
1 parent
04d5e71
commit d3ef952
Showing
8 changed files
with
25 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,14 @@ | ||
'use server' | ||
import { fetchCDNConfig } from '../server/requests' | ||
import { revalidateTag } from 'next/cache' | ||
|
||
export const invalidateConfig = async ( | ||
sdkToken: string, | ||
obfuscated: boolean, | ||
lastModified?: number, | ||
): Promise<void> => { | ||
export const invalidateConfig = async (sdkToken: string): Promise<void> => { | ||
if (typeof window != 'undefined') { | ||
console.error( | ||
'DevCycle realtime updates are only available in Next.js 14.0.5 and above. Please update your version ' + | ||
'or disable realtime updates.', | ||
) | ||
return | ||
} | ||
await invalidateConfigCache(sdkToken, obfuscated, lastModified) | ||
} | ||
|
||
export const invalidateConfigCache = async ( | ||
sdkKey: string, | ||
obfuscated: boolean, | ||
lastModified?: number, | ||
): Promise<void> => { | ||
const response = await fetchCDNConfig(sdkKey, { | ||
enableObfuscation: obfuscated, | ||
}) | ||
|
||
const lastModifiedHeader = response.headers.get('last-modified') | ||
|
||
const lastModifiedCache = new Date(lastModifiedHeader ?? 0) | ||
const lastModifiedClient = new Date(lastModified ?? 0) | ||
|
||
if ( | ||
lastModifiedHeader && | ||
lastModified && | ||
lastModifiedClient > lastModifiedCache | ||
) { | ||
console.log('Invalidating old DevCycle cached config') | ||
revalidateTag(sdkKey) | ||
} | ||
console.log('Invalidating old DevCycle cached config') | ||
revalidateTag(sdkToken) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters