The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
cache coordinates for 24 hours
Steven Tey721bd2e1a389
diff --git a/components/home/globe.tsx b/components/home/globe.tsxindex c63a020bab..d5b7f82f81 100644--- a/components/home/globe.tsx+++ b/components/home/globe.tsx@@ -142,8 +142,8 @@ const GlobeAnimation = ({ markers }: { markers: MarkerProps[] }) => {rel="noreferrer">dub.sh/github- </a>{" "}- in real time.+ </a>+ .</p><Linkhref={{ pathname: "/", query: { key: "github" } }}diff --git a/pages/api/edge/coordinates.ts b/pages/api/edge/coordinates.tsindex 44ddd8e65a..c5aa320634 100644--- a/pages/api/edge/coordinates.ts+++ b/pages/api/edge/coordinates.ts@@ -1,15 +1,27 @@import type { NextRequest } from "next/server";+import { redis } from "@/lib/upstash";export const config = {runtime: "edge",};+interface CoordinateProps {+ location: [string, string];+ size: number;+}+export default async function handler(req: NextRequest) {if (req.method === "GET") {const count = 50;let latestCoordinates = [];- if (process.env.TINYBIRD_API_KEY) {+ // Check if coordinates are cached in Redis+ const cachedCoordinates = await redis.get<CoordinateProps[]>("coordinates");+ if (cachedCoordinates) {+ latestCoordinates = cachedCoordinates;++ // if not cached in Redis, fetch from Tinybird+ } else if (process.env.TINYBIRD_API_KEY) {const response = await fetch(`https://api.us-east.tinybird.co/v0/pipes/coordinates.json`,{@@ -27,13 +39,15 @@ export default async function handler(req: NextRequest) {size: 0.075 - (0.075 / count) * idx,};});++ // cache coordinates in Redis for 24 hours+ await redis.set("coordinates", JSON.stringify(latestCoordinates), {+ ex: 86400,+ });}return new Response(JSON.stringify(latestCoordinates), {status: 200,- headers: {- "Cache-Control": "s-maxage=86400",- },});} else {return new Response(`Method ${req.method} Not Allowed`, { status: 405 });