Files
formbricks-formbricks/apps/web/lib/cache/organization.ts
2024-12-13 05:23:22 +00:00

43 lines
958 B
TypeScript

import { revalidateTag } from "next/cache";
interface RevalidateProps {
id?: string;
userId?: string;
environmentId?: string;
count?: boolean;
}
export const organizationCache = {
tag: {
byId(id: string) {
return `organizations-${id}`;
},
byUserId(userId: string) {
return `users-${userId}-organizations`;
},
byEnvironmentId(environmentId: string) {
return `environments-${environmentId}-organizations`;
},
byCount() {
return "organizations-count";
},
},
revalidate: ({ id, userId, environmentId, count }: RevalidateProps): void => {
if (id) {
revalidateTag(organizationCache.tag.byId(id));
}
if (userId) {
revalidateTag(organizationCache.tag.byUserId(userId));
}
if (environmentId) {
revalidateTag(organizationCache.tag.byEnvironmentId(environmentId));
}
if (count) {
revalidateTag(organizationCache.tag.byCount());
}
},
};