Skip to content

Commit 7c1f3b2

Browse files
committed
refactor: wording
1 parent e1d7a01 commit 7c1f3b2

File tree

6 files changed

+14
-14
lines changed

6 files changed

+14
-14
lines changed

docs/content/1.getting-started/1.index.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,15 +102,15 @@ variant: subtle
102102
---
103103
::
104104

105-
#### `CACHE_CLEANUP_UNTOUCHED_TTL_DAYS`
105+
#### `CACHE_CLEANUP_UNUSED_TTL_DAYS`
106106

107107
- Default: `30`
108108

109-
Cache entries which have not been accessed for `CACHE_CLEANUP_UNTOUCHED_TTL_DAYS` days will be automatically deleted. Set to `0` to disable.
109+
Cache entries which have not been accessed for `CACHE_CLEANUP_UNUSED_TTL_DAYS` days will be automatically deleted. Set to `0` to disable.
110110

111111
#### `CACHE_CLEANUP_TTL_DAYS`
112112

113-
Cache entries which have been created `CACHE_CLEANUP_TTL_DAYS` days ago will be automatically deleted. Set to `0` to disable.
113+
Cache entries which have been created `CACHE_CLEANUP_TTL_DAYS` days ago will be automatically deleted, regardless of when it was last accessed.
114114

115115
#### `CACHE_CLEANUP_CRON`
116116

lib/db/index.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ export async function touchKey(
193193
export async function findStaleKeys(
194194
db: DB,
195195
opts?: {
196-
untouchedTTLDays?: number
196+
unusedTTLDays?: number
197197
ttlDays?: number
198198
date?: Date
199199
},
@@ -206,9 +206,9 @@ export async function findStaleKeys(
206206
query = query.where('created_at', '<', threshold.toISOString())
207207
}
208208

209-
if (opts?.untouchedTTLDays !== undefined) {
210-
const untouchedThreshold = new Date(now.getTime() - opts.untouchedTTLDays * 24 * 60 * 60 * 1000)
211-
query = query.where('accessed_at', '<', untouchedThreshold.toISOString())
209+
if (opts?.unusedTTLDays !== undefined) {
210+
const threshold = new Date(now.getTime() - opts.unusedTTLDays * 24 * 60 * 60 * 1000)
211+
query = query.where('accessed_at', '<', threshold.toISOString())
212212
}
213213

214214
return query.selectAll().execute()

lib/env.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ const portSchema = z.coerce.number().int().min(1).max(65_535)
77
const envSchema = z.object({
88
ENABLE_DIRECT_DOWNLOADS: booleanSchema.default('false'),
99
/**
10-
* @deprecated use `CACHE_CLEANUP_UNTOUCHED_TTL_DAYS` or `CACHE_CLEANUP_TTL_DAYS` instead
10+
* @deprecated use `CACHE_CLEANUP_UNUSED_TTL_DAYS` or `CACHE_CLEANUP_TTL_DAYS` instead
1111
*/
1212
CACHE_CLEANUP_OLDER_THAN_DAYS: z.coerce.number().int().min(0).default(90),
13-
CACHE_CLEANUP_UNTOUCHED_TTL_DAYS: z.coerce.number().int().min(0).default(30),
13+
CACHE_CLEANUP_UNUSED_TTL_DAYS: z.coerce.number().int().min(0).default(30),
1414
CACHE_CLEANUP_TTL_DAYS: z.coerce.number().int().min(0).optional(),
1515
CACHE_CLEANUP_CRON: z.string().default('0 0 * * *'),
1616
UPLOAD_CLEANUP_CRON: z.string().default('*/10 * * * *'),

lib/storage/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ export const useStorageAdapter = createSingletonPromise(async () => {
184184
logger.debug('Download:', objectName)
185185
return driver.createReadStream(objectName)
186186
},
187-
async pruneCaches(opts?: { untouchedTTLDays?: number; ttlDays?: number }) {
187+
async pruneCaches(opts?: { unusedTTLDays?: number; ttlDays?: number }) {
188188
logger.debug('Prune:', opts)
189189

190190
const keys = await findStaleKeys(db, opts)

plugins/cleanup.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export default defineNitroPlugin(() => {
1414
if (
1515
ENV.CACHE_CLEANUP_OLDER_THAN_DAYS ||
1616
ENV.CACHE_CLEANUP_TTL_DAYS ||
17-
ENV.CACHE_CLEANUP_UNTOUCHED_TTL_DAYS
17+
ENV.CACHE_CLEANUP_UNUSED_TTL_DAYS
1818
) {
1919
const job = new Cron(ENV.CACHE_CLEANUP_CRON)
2020
const nextRun = job.nextRun()
@@ -25,7 +25,7 @@ export default defineNitroPlugin(() => {
2525
const adapter = await useStorageAdapter()
2626
await adapter.pruneCaches({
2727
ttlDays: ENV.CACHE_CLEANUP_TTL_DAYS,
28-
untouchedTTLDays: ENV.CACHE_CLEANUP_UNTOUCHED_TTL_DAYS ?? ENV.CACHE_CLEANUP_OLDER_THAN_DAYS,
28+
unusedTTLDays: ENV.CACHE_CLEANUP_UNUSED_TTL_DAYS ?? ENV.CACHE_CLEANUP_OLDER_THAN_DAYS,
2929
})
3030
})
3131
}

tests/cleanup.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,14 @@ describe('getting stale keys', async () => {
6161
beforeEach(() => pruneKeys(db))
6262

6363
const version = '0577ec58bee6d5415625'
64-
test('returns untouched stale keys if threshold is passed', async () => {
64+
test('returns unused stale keys if threshold is passed', async () => {
6565
const referenceDate = new Date('2024-04-01T00:00:00Z')
6666
await updateOrCreateKey(db, { key: 'cache-a', version, date: new Date('2024-01-01T00:00:00Z') })
6767
await updateOrCreateKey(db, { key: 'cache-b', version, date: new Date('2024-02-01T00:00:00Z') })
6868
await updateOrCreateKey(db, { key: 'cache-c', version, date: new Date('2024-03-15T00:00:00Z') })
6969
await updateOrCreateKey(db, { key: 'cache-d', version, date: new Date('2024-03-20T00:00:00Z') })
7070

71-
const match = await findStaleKeys(db, { untouchedTTLDays: 30, date: referenceDate })
71+
const match = await findStaleKeys(db, { unusedTTLDays: 30, date: referenceDate })
7272
expect(match.length).toBe(2)
7373

7474
const matchA = match.find((m) => m.key === 'cache-a')

0 commit comments

Comments
 (0)