mirror of
https://github.com/hanzoai/next.js.git
synced 2026-09-24 17:00:51 +00:00
### What? Fix cache-handler-redis example with working cache handler ### Why? It was not working because next-shared-cache was updated but some code inside the cache-handler.js was deprecated after version 1.0.0. When starting the app without Redis the cache handler was not switching to the LRU handler. ### How? - Updated cache-handler-redis example with working cache handler from [next-shared-cache's example](https://caching-tools.github.io/next-shared-cache/redis) - Add check for PHASE_PRODUCTION_BUILD to avoid [issues while building ](https://github.com/caching-tools/next-shared-cache/issues/284#issuecomment-1919145094) - Add throw error for Redis error to switch to the LRU handler - Updated dependencies - Updated readme broken links - Remove "version" from docker-compose's file because it's outdated [version outdated](https://github.com/docker/compose/issues/11628) Closes NEXT-66812 Fixes #66812 Co-authored-by: Delba de Oliveira <[email protected]>
69 lines
1.6 KiB
TypeScript
69 lines
1.6 KiB
TypeScript
import { notFound } from "next/navigation";
|
|
import { CacheStateWatcher } from "../cache-state-watcher";
|
|
import { Suspense } from "react";
|
|
import { RevalidateFrom } from "../revalidate-from";
|
|
import Link from "next/link";
|
|
|
|
type TimeData = {
|
|
unixtime: number;
|
|
datetime: string;
|
|
timezone: string;
|
|
};
|
|
|
|
const timeZones = ["cet", "gmt"];
|
|
|
|
export const revalidate = 500;
|
|
|
|
export async function generateStaticParams() {
|
|
return timeZones.map((timezone) => ({ timezone }));
|
|
}
|
|
|
|
export default async function Page({ params: { timezone } }) {
|
|
const data = await fetch(
|
|
`https://worldtimeapi.org/api/timezone/${timezone}`,
|
|
{
|
|
next: { tags: ["time-data"] },
|
|
},
|
|
);
|
|
|
|
if (!data.ok) {
|
|
notFound();
|
|
}
|
|
|
|
const timeData: TimeData = await data.json();
|
|
|
|
return (
|
|
<>
|
|
<header className="header">
|
|
{timeZones.map((timeZone) => (
|
|
<Link key={timeZone} className="link" href={`/${timeZone}`}>
|
|
{timeZone.toUpperCase()} Time
|
|
</Link>
|
|
))}
|
|
</header>
|
|
<main className="widget">
|
|
<div className="pre-rendered-at">
|
|
{timeData.timezone} Time {timeData.datetime}
|
|
</div>
|
|
<Suspense fallback={null}>
|
|
<CacheStateWatcher
|
|
revalidateAfter={revalidate * 1000}
|
|
time={timeData.unixtime * 1000}
|
|
/>
|
|
</Suspense>
|
|
<RevalidateFrom />
|
|
</main>
|
|
<footer className="footer">
|
|
<Link
|
|
href={process.env.NEXT_PUBLIC_REDIS_INSIGHT_URL}
|
|
className="link"
|
|
target="_blank"
|
|
rel="noopener noreferrer"
|
|
>
|
|
View RedisInsight ↪
|
|
</Link>
|
|
</footer>
|
|
</>
|
|
);
|
|
}
|