25 lines
989 B
JavaScript
25 lines
989 B
JavaScript
import { test } from 'node:test';
|
|
import assert from 'node:assert/strict';
|
|
import { createDetailCache } from '../server/detail-cache.mjs';
|
|
|
|
test('detail cache expires stale source data and supports explicit refresh', () => {
|
|
const cache = createDetailCache({ maxEntries: 2, ttlMs: 100 });
|
|
cache.set('2026/1', { tarih: '10.09.2026' }, 1000);
|
|
assert.deepEqual(cache.get('2026/1', 1099), { tarih: '10.09.2026' });
|
|
assert.equal(cache.get('2026/1', 1100), undefined);
|
|
cache.set('2026/1', { tarih: '16.09.2026' }, 1200);
|
|
assert.deepEqual(cache.get('2026/1', 1200), { tarih: '16.09.2026' });
|
|
cache.clear();
|
|
assert.equal(cache.size, 0);
|
|
});
|
|
|
|
test('detail cache evicts the oldest entry at its bounded limit', () => {
|
|
const cache = createDetailCache({ maxEntries: 2, ttlMs: 1000 });
|
|
cache.set('a', 1, 0);
|
|
cache.set('b', 2, 0);
|
|
cache.set('c', 3, 0);
|
|
assert.equal(cache.get('a', 1), undefined);
|
|
assert.equal(cache.get('b', 1), 2);
|
|
assert.equal(cache.get('c', 1), 3);
|
|
});
|