Skip to content

Commit c8f9edb

Browse files
committed
chore: test with unstable cache
1 parent 5a0694a commit c8f9edb

File tree

2 files changed

+34
-5
lines changed

2 files changed

+34
-5
lines changed

apps/insights/src/components/PriceFeed/publishers.tsx

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,14 @@ import { getStatus } from "../../status";
1111
import { PublisherIcon } from "../PublisherIcon";
1212
import { PublisherTag } from "../PublisherTag";
1313
import { PublishersCard } from "./publishers-card";
14+
import { funcA, funcAUnstableCache } from "./util";
1415

1516
type Props = {
1617
params: Promise<{
1718
slug: string;
1819
}>;
1920
};
2021

21-
const funcA = async () => {
22-
"use cache";
23-
await new Promise((resolve) => setTimeout(resolve, 2000));
24-
return Math.random();
25-
}
2622

2723
const funcB = async () => {
2824
const start = performance.now();
@@ -33,6 +29,14 @@ const funcB = async () => {
3329
return res;
3430
}
3531

32+
const funcBUnstableCache = async () => {
33+
const start = performance.now();
34+
const res = await funcAUnstableCache();
35+
const end = performance.now();
36+
// eslint-disable-next-line no-console, @typescript-eslint/restrict-template-expressions
37+
console.log(`funcBUnstableCache: ${end - start}ms`);
38+
return res;
39+
}
3640

3741
export const Publishers = async ({ params }: Props) => {
3842
const { slug } = await params;
@@ -42,13 +46,19 @@ export const Publishers = async ({ params }: Props) => {
4246
pythtestConformanceFeeds,
4347
pythnetPublishers,
4448
pythtestConformancePublishers,
49+
funcRes,
50+
funcResUnstableCache,
4551
] = await Promise.all([
4652
getFeedsCached(Cluster.Pythnet),
4753
getFeedsCached(Cluster.PythtestConformance),
4854
getPublishers(Cluster.Pythnet, symbol),
4955
getPublishers(Cluster.PythtestConformance, symbol),
5056
funcB(),
57+
funcBUnstableCache(),
5158
]);
59+
60+
// eslint-disable-next-line no-console, @typescript-eslint/restrict-template-expressions
61+
console.log(funcRes, funcResUnstableCache);
5262
const feed = pythnetFeeds.find((feed) => feed.symbol === symbol);
5363
const testFeed = pythtestConformanceFeeds.find(
5464
(feed) => feed.symbol === symbol,
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { unstable_cache } from 'next/cache';
2+
3+
export const funcA = async () => {
4+
"use cache";
5+
await new Promise((resolve) => setTimeout(resolve, 2000));
6+
return Math.random();
7+
}
8+
9+
10+
const rand = async () => {
11+
await new Promise((resolve) => setTimeout(resolve, 2000));
12+
return Math.random();
13+
}
14+
15+
export const funcAUnstableCache = unstable_cache(
16+
rand,
17+
[], // cache keys here; leave [] for simple global cache
18+
{ revalidate: 60 }, // revalidate period in seconds, or use false for infinite
19+
);

0 commit comments

Comments
 (0)