'use cache';
import { Book } from '@/books/Book';
import { NextPage } from 'next';
import { cacheLife } from 'next/cache';

async function getBooks(): Promise<Book[]> {
  const response = await fetch('http://localhost:3001/books');
  return response.json();
}

const BooksPage: NextPage = async () => {
  'use cache';
  cacheLife({
    stale: 5 * 60, // 5 Minuten
    revalidate: 45 * 60, // 45 Minuten
    expire: 2 * 24 * 60 * 60, // 2 Tage
  });
  const books = await getBooks();

  return (
    <div>
      <h1>Bücher</h1>
      <ul>
        {books.map((book) => (
          <li key={book.id}>{book.title}</li>
        ))}
      </ul>
    </div>
  );
};

export default BooksPage;
