From 59a3056c0b8343fc0d7ce42192bc6e623a922bb6 Mon Sep 17 00:00:00 2001 From: Guus van Meerveld Date: Sat, 9 Mar 2024 22:45:57 +0100 Subject: [PATCH] fixed cache not revalidating at all --- package.json | 12 +++++----- src/utils/landing.ts | 56 +++++++++++++++++++++++--------------------- yarn.lock | 18 +++++++------- 3 files changed, 44 insertions(+), 42 deletions(-) diff --git a/package.json b/package.json index 8446bd8..587b9e0 100644 --- a/package.json +++ b/package.json @@ -19,6 +19,7 @@ "@nextui-org/react": "^2.2.10", "@prisma/client": "4.10.1", "@tanstack/react-query": "^4.24.9", + "autoprefixer": "^10.4.18", "axios": "^1.1.2", "bcrypt": "^5.1.0", "framer-motion": "^11.0.8", @@ -26,22 +27,21 @@ "iron-session": "^6.3.1", "next": "^14.1.1", "next-themes": "^0.2.1", + "postcss": "^8.4.35", "react": "^18.2.0", "react-dom": "^18.2.0", "react-icons": "^5.0.1", + "tailwindcss": "^3.4.1", "timeago.js": "^4.0.2", - "zod": "^3.20.6", - "autoprefixer": "^10.4.18", - "postcss": "^8.4.35", - "tailwindcss": "^3.4.1" + "zod": "^3.20.6" }, "devDependencies": { "@trivago/prettier-plugin-sort-imports": "^4.0.0", "@types/bcrypt": "^5.0.0", "@types/fs-extra": "^11.0.4", "@types/node": "^15.12.1", - "@types/react": "^17.0.9", - "@types/react-dom": "^17.0.6", + "@types/react": "^18.2.64", + "@types/react-dom": "^18.2.21", "eslint": "^7.28.0", "eslint-config-next": "13.1.6", "prettier": "^2.3.1", diff --git a/src/utils/landing.ts b/src/utils/landing.ts index 174a2e9..45478b7 100644 --- a/src/utils/landing.ts +++ b/src/utils/landing.ts @@ -3,44 +3,46 @@ import path from "path"; import { avatarFileFormat } from "./constants"; +import { cache } from "react"; + import Landing, { LandingModel } from "@models/landing"; import exists from "@utils/fileExists"; -export const readLandingJson = async ( - dataDirLocation: string -): Promise => { - const landingJsonLocation = path.join(dataDirLocation, "landing.json"); +export const readLandingJson = cache( + async (dataDirLocation: string): Promise => { + const landingJsonLocation = path.join(dataDirLocation, "landing.json"); - const fileExists = await exists(landingJsonLocation); + const fileExists = await exists(landingJsonLocation); - if (!fileExists) { - throw new Error( - `Could not find landing json file at: ${landingJsonLocation}` - ); - } + if (!fileExists) { + throw new Error( + `Could not find landing json file at: ${landingJsonLocation}` + ); + } - const rawJson: unknown = await readJson(landingJsonLocation); + const rawJson: unknown = await readJson(landingJsonLocation); - const landingResult = LandingModel.safeParse(rawJson); + const landingResult = LandingModel.safeParse(rawJson); - if (!landingResult.success) - throw new Error(`Failed to parse landing json: ${landingResult.error}`); + if (!landingResult.success) + throw new Error(`Failed to parse landing json: ${landingResult.error}`); - return landingResult.data; -}; + return landingResult.data; + } +); -export const readAvatarFile = async ( - dataDirLocation: string -): Promise => { - const avatarFileLocation = path.join( - dataDirLocation, - `avatar.${avatarFileFormat}` - ); +export const readAvatarFile = cache( + async (dataDirLocation: string): Promise => { + const avatarFileLocation = path.join( + dataDirLocation, + `avatar.${avatarFileFormat}` + ); - const imageData = await readFile(avatarFileLocation); + const imageData = await readFile(avatarFileLocation); - const base64Image = Buffer.from(imageData).toString("base64"); + const base64Image = Buffer.from(imageData).toString("base64"); - return `data:image/${avatarFileFormat};base64,${base64Image}`; -}; + return `data:image/${avatarFileFormat};base64,${base64Image}`; + } +); diff --git a/yarn.lock b/yarn.lock index af94aae..9b97a51 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2279,17 +2279,17 @@ resolved "https://registry.yarnpkg.com/@types/range-parser/-/range-parser-1.2.7.tgz#50ae4353eaaddc04044279812f52c8c65857dbcb" integrity sha512-hKormJbkJqzQGhziax5PItDUTMAM9uE2XXQmM37dyd4hVM+5aVl7oVxMVUiVQn2oCQFN/LKCZdvSM0pFRqbSmQ== -"@types/react-dom@^17.0.6": - version "17.0.25" - resolved "https://registry.yarnpkg.com/@types/react-dom/-/react-dom-17.0.25.tgz#e0e5b3571e1069625b3a3da2b279379aa33a0cb5" - integrity sha512-urx7A7UxkZQmThYA4So0NelOVjx3V4rNFVJwp0WZlbIK5eM4rNJDiN3R/E9ix0MBh6kAEojk/9YL+Te6D9zHNA== +"@types/react-dom@^18.2.21": + version "18.2.21" + resolved "https://registry.yarnpkg.com/@types/react-dom/-/react-dom-18.2.21.tgz#b8c81715cebdebb2994378616a8d54ace54f043a" + integrity sha512-gnvBA/21SA4xxqNXEwNiVcP0xSGHh/gi1VhWv9Bl46a0ItbTT5nFY+G9VSQpaG/8N/qdJpJ+vftQ4zflTtnjLw== dependencies: - "@types/react" "^17" + "@types/react" "*" -"@types/react@^17", "@types/react@^17.0.9": - version "17.0.75" - resolved "https://registry.yarnpkg.com/@types/react/-/react-17.0.75.tgz#cffbc76840a12fcadaf5a3cf14878bb06efcf73d" - integrity sha512-MSA+NzEzXnQKrqpO63CYqNstFjsESgvJAdAyyJ1n6ZQq/GLgf6nOfIKwk+Twuz0L1N6xPe+qz5xRCJrbhMaLsw== +"@types/react@*", "@types/react@^18.2.64": + version "18.2.64" + resolved "https://registry.yarnpkg.com/@types/react/-/react-18.2.64.tgz#3700fbb6b2fa60a6868ec1323ae4cbd446a2197d" + integrity sha512-MlmPvHgjj2p3vZaxbQgFUQFvD8QiZwACfGqEdDSWou5yISWxDQ4/74nCAwsUiX7UFLKZz3BbVSPj+YxeoGGCfg== dependencies: "@types/prop-types" "*" "@types/scheduler" "*"