-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #867 from dpc-sdp/bugfix/section-tags
feat(@dpc-sdp/ripple-tide-api): merged site+alert cache tags with page cache tags
- Loading branch information
Showing
5 changed files
with
66 additions
and
8 deletions.
There are no files selected for viewing
33 changes: 33 additions & 0 deletions
33
packages/nuxt-ripple/composables/use-merge-section-tags.ts
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 |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { setResponseHeader, getResponseHeaders } from 'h3' | ||
|
||
// Merge two section cache tags string and deduplicate tag | ||
// Return a string of merged tags | ||
const mergeTags = (existingTags: string, newTags: string): string => { | ||
const tags1 = existingTags.split(' ') | ||
const tags2 = newTags.split(' ') | ||
const tags = [...new Set([...tags1, ...tags2])] | ||
return tags.join(' ') | ||
} | ||
|
||
export const useMergeSectionTags = async ( | ||
sectionCacheTags: any | ||
): Promise<void> => { | ||
const event = useRequestEvent() | ||
// Section.io cache tags must be set on the response header to invalidate the cache after a change in drupal | ||
if (sectionCacheTags) { | ||
const currentResponseHeaders = getResponseHeaders(event) | ||
|
||
const currentSectionTags: string = | ||
currentResponseHeaders && currentResponseHeaders['section-cache-tags'] | ||
? (currentResponseHeaders['section-cache-tags'] as string) | ||
: ('' as string) | ||
|
||
setResponseHeader( | ||
event, | ||
'section-cache-tags', | ||
mergeTags(currentSectionTags, sectionCacheTags) | ||
) | ||
} | ||
} | ||
|
||
export default useMergeSectionTags |
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