diff --git a/web/pages/api/v0/market/[id]/index.ts b/web/pages/api/v0/market/[id]/index.ts index eb238dab..72e7cdbc 100644 --- a/web/pages/api/v0/market/[id]/index.ts +++ b/web/pages/api/v0/market/[id]/index.ts @@ -4,6 +4,7 @@ import { listAllComments } from 'web/lib/firebase/comments' import { getContractFromId } from 'web/lib/firebase/contracts' import { applyCorsHeaders, CORS_UNRESTRICTED } from 'web/lib/api/cors' import { FullMarket, ApiError, toFullMarket } from '../../_types' +import { marketCacheStrategy } from '../../markets' export default async function handler( req: NextApiRequest, @@ -24,6 +25,6 @@ export default async function handler( return } - res.setHeader('Cache-Control', 'max-age=0') + res.setHeader('Cache-Control', marketCacheStrategy) return res.status(200).json(toFullMarket(contract, comments, bets)) } diff --git a/web/pages/api/v0/market/[id]/lite.ts b/web/pages/api/v0/market/[id]/lite.ts index 7688caa8..6ac28db4 100644 --- a/web/pages/api/v0/market/[id]/lite.ts +++ b/web/pages/api/v0/market/[id]/lite.ts @@ -2,6 +2,7 @@ import { NextApiRequest, NextApiResponse } from 'next' import { getContractFromId } from 'web/lib/firebase/contracts' import { applyCorsHeaders, CORS_UNRESTRICTED } from 'web/lib/api/cors' import { ApiError, toLiteMarket, LiteMarket } from '../../_types' +import { marketCacheStrategy } from '../../markets' export default async function handler( req: NextApiRequest, @@ -18,6 +19,6 @@ export default async function handler( return } - res.setHeader('Cache-Control', 'max-age=0') + res.setHeader('Cache-Control', marketCacheStrategy) return res.status(200).json(toLiteMarket(contract)) } diff --git a/web/pages/api/v0/markets.ts b/web/pages/api/v0/markets.ts index 78c54772..bad6a145 100644 --- a/web/pages/api/v0/markets.ts +++ b/web/pages/api/v0/markets.ts @@ -6,6 +6,8 @@ import { toLiteMarket, ValidationError } from './_types' import { z } from 'zod' import { validate } from './_validate' +export const marketCacheStrategy = 's-maxage=15, stale-while-revalidate=45' + const queryParams = z .object({ limit: z @@ -39,7 +41,7 @@ export default async function handler( try { const contracts = await listAllContracts(limit, before) // Serve from Vercel cache, then update. see https://vercel.com/docs/concepts/functions/edge-caching - res.setHeader('Cache-Control', 's-maxage=1, stale-while-revalidate') + res.setHeader('Cache-Control', marketCacheStrategy) res.status(200).json(contracts.map(toLiteMarket)) } catch (e) { res.status(400).json({