feat(ui): note the idle eviction window on the stats page

The stats page now reads idle_ttl from the stats API. It shows
"Cached items not requested for 7 days are removed." in an info alert.
The note stays hidden when idle eviction is off.
This commit is contained in:
2026-11-23 12:50:00 +00:00
parent d6edd40d79
commit 9a44683fbd
5 changed files with 83 additions and 1 deletions
+15
View File
@@ -0,0 +1,15 @@
import { describe, expect, it } from 'vitest'
import { formatDuration } from './format'
describe('formatDuration', () => {
it.each([
[604800, '7 days'],
[86400, '1 day'],
[129600, '36 hours'],
[3600, '1 hour'],
[5400, '90 minutes'],
[60, '1 minute'],
])('formats %i seconds as %s', (seconds, expected) => {
expect(formatDuration(seconds)).toBe(expected)
})
})
+15
View File
@@ -11,6 +11,21 @@ export function formatBytes(bytes: number): string {
return Math.round((bytes / Math.pow(BYTES_PER_UNIT, i)) * 100) / 100 + ' ' + BYTE_UNITS[i]
}
const SECONDS_PER_DAY = 86400
const SECONDS_PER_HOUR = 3600
const SECONDS_PER_MINUTE = 60
function plural(n: number, unit: string): string {
return `${n} ${unit}${n === 1 ? '' : 's'}`
}
/** Whole days, hours or minutes, using the largest unit that divides the span evenly. */
export function formatDuration(seconds: number): string {
if (seconds % SECONDS_PER_DAY === 0) return plural(seconds / SECONDS_PER_DAY, 'day')
if (seconds % SECONDS_PER_HOUR === 0) return plural(seconds / SECONDS_PER_HOUR, 'hour')
return plural(Math.round(seconds / SECONDS_PER_MINUTE), 'minute')
}
export function formatDate(date: string): string {
if (!date) return 'N/A'
const parsed = new Date(date)