Przeglądaj źródła

产品详情页缓存修改

fogwind 1 tydzień temu
rodzic
commit
0cf369154e

+ 2 - 2
src/app/(public)/product/[...urlProduct]/page.tsx

@@ -30,12 +30,12 @@ import {
 
 // export const dynamic = 'auto'
 // // 'auto' | 'force-dynamic' | 'error' | 'force-static'
-
+export const dynamic = 'force-dynamic';
 async function getSingleProduct(urlKey: string) {
 
   try {
     const {data:dataById} = await cachedProductRequest<SingleProductResponse>(
-      urlKey, // 产品名称
+      // urlKey, // 产品名称
       GET_PRODUCT_BY_URL_KEY, // gql查询语句
       { urlKey: urlKey },
     );

+ 1 - 1
src/components/catalog/product/RelatedProductsSection.tsx

@@ -11,7 +11,7 @@ export async function RelatedProductsSection({
     async function getRelatedProduct(urlKey: string) {
       try {
         const {data:dataById} = await cachedProductRequest<SingleProductResponse>(
-          urlKey,
+          // urlKey,
           GET_RELATED_PRODUCTS,
           {
             urlKey: urlKey,

+ 1 - 1
src/utils/hooks/getProductReviews.ts

@@ -8,7 +8,7 @@ export async function getProductReviews(productId: string) {
     const variables = { product_id: Number(productId), first: 10 };
     
     const {data:response} = await cachedProductRequest<any>(
-      productId,
+      // productId,
       GET_PRODUCT_REVIEWS,
       variables
     );

+ 1 - 1
src/utils/hooks/getProductSwatchAndReview.ts

@@ -6,7 +6,7 @@ import { cachedProductRequest } from "@/utils/hooks/useCache";
 export async function getProductWithSwatchAndReview(urlKey: string) {
   try {
     const {data:dataById} = await cachedProductRequest<SingleProductResponse>(
-      urlKey,
+      // urlKey,
       GET_PRODUCT_SWATCH_REVIEW,
       { urlKey: urlKey }
     );

+ 10 - 8
src/utils/hooks/useCache.ts

@@ -55,13 +55,15 @@ export function getPageCacheConfig(
 /**
  * Helper to create dynamic product cache config with specific product identifier
  */
-export function getProductCacheConfig(productId: string): PageCacheConfig {
-  return {
-    tags: ["products", `product-${productId}`],
-    life: "hours",
-  };
+// export function getProductCacheConfig(productId: string): PageCacheConfig {
+//   return {
+//     tags: ["products", `product-${productId}`],
+//     life: "hours",
+//   };
+// }
+export function getProductCacheConfig(): {noCache: boolean} {
+  return {noCache: true};
 }
-
 /**
  * Helper to create dynamic category cache config with specific category identifier
  */
@@ -95,11 +97,11 @@ export async function cachedProductRequest<
   TData = unknown,
   TVariables extends OperationVariables = OperationVariables,
 >(
-  productId: string,
+  // productId: string,
   query: DocumentNode,
   variables?: TVariables,
 ): Promise<GraphqlRequestResult<TData>> {
-  const config = getProductCacheConfig(productId);
+  const config = getProductCacheConfig();
   return graphqlRequest<TData, TVariables>(query, variables, config);
 }