Skip to content

Commit

Permalink
chore(cache): set 30 seconds cache expiration #276
Browse files Browse the repository at this point in the history
  • Loading branch information
wazolab committed Dec 10, 2024
1 parent 723cd65 commit aee1ab7
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions pages/[project]/changes_logs.vue
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ const projectSlug = route.params.project as string
//
// Data Fetching
//
// TODO: Invalid cache key based on data refresh-timing (set on API-side)
const { data, status, refresh } = useAsyncData(
`changes_logs-${projectSlug}`,
async () => {
Expand Down Expand Up @@ -57,13 +56,28 @@ const { data, status, refresh } = useAsyncData(
},
{
getCachedData(key) {
return nuxtApp.payload.data[key] || nuxtApp.static.data[key]
const data = nuxtApp.payload.data[key] || nuxtApp.static.data[key]
if (!data) {
return null
}
const expirationDate = new Date(data.fetchedAt)
expirationDate.setTime(expirationDate.getTime() + 30 * 1000)
const isExpired = expirationDate.getTime() < Date.now()
if (isExpired) {
return null
}
return data
},
transform: ({ project, loChas }) => {
return {
project,
loChas,
logs: loChas.map((loCha) => loCha.objects).flat(),
fetchedAt: new Date(),
}
},
},
Expand Down

0 comments on commit aee1ab7

Please sign in to comment.