Skip to content

Commit e8af572

Browse files
committed
set same revalidate time to cache timeout
1 parent ae26c6a commit e8af572

File tree

3 files changed

+20
-8
lines changed

3 files changed

+20
-8
lines changed

src/lib/utils/data/dataLoader.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export async function dataLoader<T extends unknown[]>(
2323
loaders: {
2424
[K in keyof T]: [string, DataLoaderFunction<T[K]>]
2525
},
26-
cacheTimeout: number = 1000 * 60 * 60 // 1 hour
26+
cacheTimeout?: number
2727
): Promise<T> {
2828
const cachedLoaders = loaders.map(([key, loader]) => {
2929
const cachedLoader = cacheAsyncFn(key, loader, {

src/pages/stablecoins.tsx

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,9 @@ type Props = BasePageProps & {
9090
marketsHasError: boolean
9191
}
9292

93+
// In seconds
94+
const REVALIDATE_TIME = BASE_TIME_UNIT * 24 * 7
95+
9396
export const getStaticProps = (async ({ locale }) => {
9497
const lastDeployDate = getLastDeployDate()
9598
const lastDeployLocaleTimestamp = getLocaleTimestamp(
@@ -137,10 +140,13 @@ export const getStaticProps = (async ({ locale }) => {
137140
try {
138141
const [ethereumEcosystemData, stablecoinsData] = await dataLoader<
139142
[EthereumDataResponse, StablecoinDataResponse]
140-
>([
141-
["ethereumEcosystemData", fetchEthereumEcosystemData],
142-
["ethereumStablecoinsData", fetchEthereumStablecoinsData],
143-
])
143+
>(
144+
[
145+
["ethereumEcosystemData", fetchEthereumEcosystemData],
146+
["ethereumStablecoinsData", fetchEthereumStablecoinsData],
147+
],
148+
REVALIDATE_TIME * 1000
149+
)
144150

145151
// Get the intersection of stablecoins and Ethereum tokens to only have a list of data for stablecoins in the Ethereum ecosystem
146152
const ethereumStablecoinData = stablecoinsData.filter(
@@ -185,7 +191,7 @@ export const getStaticProps = (async ({ locale }) => {
185191
marketsHasError,
186192
},
187193
// Updated once a week
188-
revalidate: BASE_TIME_UNIT * 24 * 7,
194+
revalidate: REVALIDATE_TIME,
189195
}
190196
}) satisfies GetStaticProps<Props>
191197

src/pages/staking/index.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,9 @@ type Props = BasePageProps & {
153153
data: StakingStatsData
154154
}
155155

156+
// In seconds
157+
const REVALIDATE_TIME = BASE_TIME_UNIT * 24
158+
156159
export const getStaticProps = (async ({ locale }) => {
157160
const lastDeployDate = getLastDeployDate()
158161
const lastDeployLocaleTimestamp = getLocaleTimestamp(
@@ -164,7 +167,10 @@ export const getStaticProps = (async ({ locale }) => {
164167

165168
const contentNotTranslated = !existsNamespace(locale!, requiredNamespaces[2])
166169

167-
const [data] = await dataLoader([["stakingStatsData", fetchBeaconchainData]])
170+
const [data] = await dataLoader(
171+
[["stakingStatsData", fetchBeaconchainData]],
172+
REVALIDATE_TIME * 1000
173+
)
168174

169175
return {
170176
props: {
@@ -174,7 +180,7 @@ export const getStaticProps = (async ({ locale }) => {
174180
lastDeployLocaleTimestamp,
175181
},
176182
// Updated once a day
177-
revalidate: BASE_TIME_UNIT * 24,
183+
revalidate: REVALIDATE_TIME,
178184
}
179185
}) satisfies GetStaticProps<Props>
180186

0 commit comments

Comments
 (0)