Skip to content

Commit 2b24781

Browse files
committed
refactor: extract constant
1 parent c7dcdac commit 2b24781

2 files changed

Lines changed: 3 additions & 1 deletion

File tree

server/utils/npm.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import type { Packument } from '#shared/types'
22
import { encodePackageName, fetchLatestVersion as _fetchLatestVersion } from '#shared/utils/npm'
33
import { maxSatisfying, prerelease } from 'semver'
4+
import { CACHE_MAX_AGE_FIVE_MINUTES } from '#shared/utils/constants'
45

56
const NPM_REGISTRY = 'https://registry.npmjs.org'
67

@@ -10,7 +11,7 @@ export const fetchNpmPackage = defineCachedFunction(
1011
return await $fetch<Packument>(`${NPM_REGISTRY}/${encodedName}`)
1112
},
1213
{
13-
maxAge: 60 * 5,
14+
maxAge: CACHE_MAX_AGE_FIVE_MINUTES,
1415
swr: true,
1516
name: 'npm-package',
1617
getKey: (name: string) => name,

shared/utils/constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// Duration
22
export const CACHE_MAX_AGE_ONE_MINUTE = 60
3+
export const CACHE_MAX_AGE_FIVE_MINUTES = 60 * 5
34
export const CACHE_MAX_AGE_ONE_HOUR = 60 * 60
45
export const CACHE_MAX_AGE_ONE_DAY = 60 * 60 * 24
56
export const CACHE_MAX_AGE_ONE_YEAR = 60 * 60 * 24 * 365

0 commit comments

Comments
 (0)