mirror of
https://github.com/formbricks/formbricks.git
synced 2025-12-30 18:30:32 -06:00
Co-authored-by: Johannes <johannes@formbricks.com> Co-authored-by: Matthias Nannt <mail@matthiasnannt.com>
35 lines
848 B
TypeScript
35 lines
848 B
TypeScript
import { revalidateTag } from "next/cache";
|
|
|
|
interface RevalidateProps {
|
|
id?: string;
|
|
environmentId?: string;
|
|
attributeClassName?: string;
|
|
}
|
|
|
|
export const segmentCache = {
|
|
tag: {
|
|
byId(id: string) {
|
|
return `segment-${id}`;
|
|
},
|
|
byEnvironmentId(environmentId: string): string {
|
|
return `environments-${environmentId}-segements`;
|
|
},
|
|
byAttributeClassName(attributeClassName: string): string {
|
|
return `attribute-${attributeClassName}-segements`;
|
|
},
|
|
},
|
|
revalidate({ id, environmentId, attributeClassName }: RevalidateProps): void {
|
|
if (id) {
|
|
revalidateTag(this.tag.byId(id));
|
|
}
|
|
|
|
if (environmentId) {
|
|
revalidateTag(this.tag.byEnvironmentId(environmentId));
|
|
}
|
|
|
|
if (attributeClassName) {
|
|
revalidateTag(this.tag.byAttributeClassName(attributeClassName));
|
|
}
|
|
},
|
|
};
|