Skip to content

Commit

Permalink
create cache constant variable for client-side cache
Browse files Browse the repository at this point in the history
  • Loading branch information
Aliiiu committed Jan 8, 2025
1 parent a4cdb58 commit 6618c9e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
7 changes: 5 additions & 2 deletions src/services/gasPrice/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { HYDRATE } from 'next-redux-wrapper'
import { createApi, fetchBaseQuery } from '@reduxjs/toolkit/query/react'

const REFETCH_INTERVAL = 60 * 30
const CACHE_DURATION = 60 * 60

export const gasPriceApi = createApi({
reducerPath: 'gasPriceApi',
extractRehydrationInfo(action, { reducerPath }) {
Expand All @@ -12,8 +15,8 @@ export const gasPriceApi = createApi({
baseQuery: fetchBaseQuery({
baseUrl: '/api/gas-price',
}),
refetchOnMountOrArgChange: 60 * 30,
keepUnusedDataFor: 60 * 60,
refetchOnMountOrArgChange: REFETCH_INTERVAL,
keepUnusedDataFor: CACHE_DURATION,
tagTypes: ['GasPrice'],
refetchOnFocus: true,
endpoints: (builder) => ({
Expand Down
7 changes: 5 additions & 2 deletions src/services/treasury/restApi/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ import { createApi, fetchBaseQuery } from '@reduxjs/toolkit/query/react'
import { HYDRATE } from 'next-redux-wrapper'
import { fraxLendQueryObject } from '../queries'

const REFETCH_INTERVAL = 60 * 30
const CACHE_DURATION = 60 * 60

export type TResponseData = {
response: ContractDetailsType[]
}
Expand Down Expand Up @@ -53,8 +56,8 @@ export const treasuryRestApi = createApi({
return null
},
baseQuery: customBaseQuery,
refetchOnMountOrArgChange: 60 * 30,
keepUnusedDataFor: 60 * 60,
refetchOnMountOrArgChange: REFETCH_INTERVAL,
keepUnusedDataFor: CACHE_DURATION,
refetchOnFocus: true,
tagTypes: ['Tokens', 'Protocols', 'TokenInfo'],
endpoints: (builder) => ({
Expand Down

0 comments on commit 6618c9e

Please sign in to comment.