Skip to content

Commit

Permalink
fix_cach
Browse files Browse the repository at this point in the history
  • Loading branch information
YAlorenzo committed May 22, 2024
1 parent 89bf38d commit 0ee035b
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
4 changes: 3 additions & 1 deletion app/api/cron/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ import Product from "@/lib/models/product.model";
import { scrapeAmazonProduct } from "@/lib/scraper";
import { generateEmailBody, sendEmail } from "@/lib/nodemailer";

export const maxDuration = 60;
// export const maxDuration = 60;
export const dynamic = "force-dynamic";
export const revalidate = 0;

export async function GET(request: Request) {
try {
Expand Down
5 changes: 3 additions & 2 deletions app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ import HeroCarousel from '@/components/HeroCarousel';
import Searchbar from '@/components/Searchbar';
import Image from 'next/image'
import { getAllProducts } from '@/lib/actions';
import React from 'react'
import React, { useEffect } from 'react'
import ProductCard from '@/components/ProductCard';
import { revalidatePath } from 'next/cache';

const Home = async () => {

const allProducts = await getAllProducts();
console.log(allProducts);

return (
<>
<section className="px-6 md:px-20 py-24">
Expand Down
6 changes: 4 additions & 2 deletions lib/actions/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"use server";

// import { revalidatePath } from "next/cache";
import { revalidatePath } from "next/cache";
import Product from "../models/product.model";
import { connectToDB } from "../mongoose";
import { scrapeAmazonProduct } from "../scraper";
Expand Down Expand Up @@ -44,7 +44,7 @@ export async function scrapeAndStoreProduct(productUrl: string) {
{ upsert: true, new: true }
);

// revalidatePath(`/products/${newProduct._id}`);
revalidatePath(`/products/${newProduct._id}`);
} catch (error: any) {
throw new Error(`Failed to create/update product: ${error.message}`);
}
Expand All @@ -69,6 +69,8 @@ export async function getAllProducts() {
connectToDB();

const products = await Product.find();

revalidatePath('/');
console.log(products);
return products;

Expand Down

0 comments on commit 0ee035b

Please sign in to comment.