mirror of
https://github.com/formbricks/formbricks.git
synced 2026-01-31 20:39:11 -06:00
Co-authored-by: pandeymangg <anshuman.pandey9999@gmail.com> Co-authored-by: Piyush Gupta <piyushguptaa2z123@gmail.com>
51 lines
1.2 KiB
TypeScript
51 lines
1.2 KiB
TypeScript
import { revalidateTag } from "next/cache";
|
|
|
|
interface RevalidateProps {
|
|
id?: string;
|
|
surveyId?: string;
|
|
personId?: string | null;
|
|
userId?: string;
|
|
environmentId?: string;
|
|
}
|
|
|
|
export const displayCache = {
|
|
tag: {
|
|
byId(id: string) {
|
|
return `displays-${id}`;
|
|
},
|
|
bySurveyId(surveyId: string) {
|
|
return `surveys-${surveyId}-displays`;
|
|
},
|
|
byPersonId(personId: string) {
|
|
return `people-${personId}-displays`;
|
|
},
|
|
byEnvironmentIdAndUserId(environmentId: string, userId: string) {
|
|
return `environments-${environmentId}-users-${userId}-displays`;
|
|
},
|
|
byEnvironmentId(environmentId: string) {
|
|
return `environments-${environmentId}-displays`;
|
|
},
|
|
},
|
|
revalidate({ id, surveyId, personId, environmentId, userId }: RevalidateProps): void {
|
|
if (environmentId && userId) {
|
|
revalidateTag(this.tag.byEnvironmentIdAndUserId(environmentId, userId));
|
|
}
|
|
|
|
if (id) {
|
|
revalidateTag(this.tag.byId(id));
|
|
}
|
|
|
|
if (surveyId) {
|
|
revalidateTag(this.tag.bySurveyId(surveyId));
|
|
}
|
|
|
|
if (personId) {
|
|
revalidateTag(this.tag.byPersonId(personId));
|
|
}
|
|
|
|
if (environmentId) {
|
|
revalidateTag(this.tag.byEnvironmentId(environmentId));
|
|
}
|
|
},
|
|
};
|