Skip to content

Commit ba5747a

Browse files
committed
Opt into caching where appropiate
1 parent 441a76a commit ba5747a

File tree

6 files changed

+24
-0
lines changed

6 files changed

+24
-0
lines changed

src/app/[...parts]/_page/BundlephobiaDiff.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ const BundlephobiaDiffInner = async ({
2121
a,
2222
b,
2323
}: BundlephobiaDiffProps) => {
24+
"use cache";
25+
2426
const { result, time } = await measuredPromise(bundlephobia(specs));
2527

2628
if (result == null) {

src/app/[...parts]/_page/NpmDiff/NpmDiff.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type { Options } from "libnpmdiff";
2+
import { cacheLife } from "next/cache";
23
import { Suspense } from "react";
34
import type { FileData } from "react-diff-view";
45
import Stack from "^/components/ui/Stack";
@@ -18,6 +19,10 @@ export interface NpmDiffProps {
1819
}
1920

2021
const NpmDiff = async ({ a, b, specs, options }: NpmDiffProps) => {
22+
"use cache";
23+
24+
cacheLife("max");
25+
2126
const diff = await npmDiff(specs, options);
2227

2328
const files: FileData[] = gitDiffParse(diff);

src/app/[...parts]/_page/PackagephobiaDiff.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ const PackagephobiaDiffInner = async ({
1818
a,
1919
b,
2020
}: PackagephobiaDiffProps) => {
21+
"use cache";
22+
2123
const { result, time } = await measuredPromise(packagephobia(specs));
2224

2325
if (result == null) {

src/lib/api/npm/getVersionData.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { cacheLife } from "next/cache";
12
import type SimplePackageSpec from "^/lib/SimplePackageSpec";
23
import { simplePackageSpecToString } from "^/lib/SimplePackageSpec";
34
import packument from "./packument";
@@ -18,6 +19,10 @@ export type VersionMap = {
1819
async function getVersionData(
1920
spec: string | SimplePackageSpec,
2021
): Promise<VersionMap> {
22+
"use cache";
23+
24+
cacheLife("hours");
25+
2126
const specString =
2227
typeof spec === "string" ? spec : simplePackageSpecToString(spec);
2328

src/lib/destination/canonicalSpec.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { cacheLife } from "next/cache";
12
import npa, { type AliasResult } from "npm-package-arg";
23
import pacote from "pacote";
34

@@ -58,6 +59,10 @@ async function handleNpaResult(result: npa.Result): Promise<string> {
5859
* - https://docs.npmjs.com/cli/v7/commands/npm-install
5960
*/
6061
function canonicalSpec(spec: string): Promise<string> {
62+
"use cache";
63+
64+
cacheLife("hours");
65+
6166
const result = npa(spec);
6267

6368
return handleNpaResult(result);

src/lib/npmDiff/npmDiff.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import libnpmdiff, { type Options } from "libnpmdiff";
2+
import { cacheLife } from "next/cache";
23

34
interface ErrorETARGET {
45
code: "ETARGET";
@@ -18,6 +19,10 @@ async function npmDiff(
1819
specs: [string, string],
1920
options: Options,
2021
): Promise<string> {
22+
"use cache";
23+
24+
cacheLife("max");
25+
2126
let startTime = 0;
2227
try {
2328
startTime = Date.now();

0 commit comments

Comments
 (0)