Skip to content

Commit f161a94

Browse files
authored
chore: set vault metadata cache ttl to 1 hour
## Why Vault metadata JSON should refresh on the same one-hour cadence as the vault prices parquet file, reducing worst-case staleness for frontend vault data. ## Lessons learnt The parquet cache was already using a one-hour local refresh interval; only the top-vault JSON in-memory and HTTP response cache still used a two-hour TTL. ## Summary - Changed top-vault metadata in-memory caches from 2 hours to 1 hour. - Changed `/top-vaults/all-data` and `/top-vaults/chart-data` `Cache-Control` max-age from 7200s to 3600s. - Updated the focused integration expectation and vault data docs.
1 parent eb9d430 commit f161a94

6 files changed

Lines changed: 9 additions & 9 deletions

File tree

docs/vault-data-optimisation-plan.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ The landing page vault data was optimised in PR #1171 by pre-computing aggregate
77
## Completed (PR #1171)
88

99
- Landing page embeds only top 30 slim vaults + pre-computed aggregates (~15 KB vs ~1.3 MB)
10-
- `/top-vaults/chart-data` endpoint with in-memory Brotli cache (2h TTL)
10+
- `/top-vaults/chart-data` endpoint with in-memory Brotli cache (1h TTL)
1111
- Integration tests for compressed/uncompressed responses
1212

1313
## Candidates for optimisation
@@ -59,6 +59,6 @@ Fetches full vaults only to match YAML strategies by `address`. Could:
5959

6060
## Implementation notes
6161

62-
- The `/top-vaults/chart-data` endpoint already has an in-memory cache with 2h TTL and Brotli pre-compression. Other server-side code could import the same caching function rather than creating a new endpoint.
62+
- The `/top-vaults/chart-data` endpoint already has an in-memory cache with 1h TTL and Brotli pre-compression. Other server-side code could import the same caching function rather than creating a new endpoint.
6363
- The vault detail page is the only route that genuinely needs full `VaultInfo`. All listing/summary views work with `SlimVaultInfo`.
6464
- Chart pages with `ssr=false` don't embed data in HTML at all — they fetch client-side. These could use the chart-data endpoint directly.

docs/vault-data-source.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,6 @@ FRED (fred.stlouisfed.org)
145145

146146
For local development, ensure R2 credentials are set in `.env.local`. All data sources will work automatically:
147147

148-
- Top vaults JSON is fetched on first page load and cached in memory
148+
- Top vaults JSON is fetched on first page load and cached in memory for 1 hour
149149
- Vault prices parquet (~150 MB) is downloaded on first metrics request and cached locally with a 1-hour refresh interval
150150
- Treasury benchmark data is fetched from FRED on demand (no credentials needed) and cached for 24 hours

src/lib/top-vaults/cache.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { fetchTopVaults } from './client';
22
import type { TopVaults } from './schemas';
33

4-
const CACHE_TTL_MS = 2 * 60 * 60 * 1000; // 2 hours
4+
const CACHE_TTL_MS = 60 * 60 * 1000; // 1 hour
55

66
let cache: { data: TopVaults; expires: number } | null = null;
77

src/routes/top-vaults/all-data/+server.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { getCachedTopVaults } from '$lib/top-vaults/cache';
44

55
const compress = promisify(brotliCompress);
66

7-
const CACHE_TTL_MS = 2 * 60 * 60 * 1000; // 2 hours
7+
const CACHE_TTL_MS = 60 * 60 * 1000; // 1 hour
88

99
let brCache: { json: string; br: Uint8Array; expires: number } | null = null;
1010

@@ -25,7 +25,7 @@ async function getCachedAllData(fetch: Fetch) {
2525
}
2626

2727
const cacheHeaders = {
28-
'cache-control': 'public, max-age=7200',
28+
'cache-control': 'public, max-age=3600',
2929
'content-type': 'application/json',
3030
vary: 'Accept-Encoding'
3131
};

src/routes/top-vaults/chart-data/+server.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { slimVault } from '$lib/top-vaults/helpers';
55

66
const compress = promisify(brotliCompress);
77

8-
const CACHE_TTL_MS = 2 * 60 * 60 * 1000; // 2 hours
8+
const CACHE_TTL_MS = 60 * 60 * 1000; // 1 hour
99

1010
let cache: { json: string; br: Uint8Array; expires: number } | null = null;
1111

@@ -26,7 +26,7 @@ async function getCachedChartData(fetch: Fetch) {
2626
}
2727

2828
const cacheHeaders = {
29-
'cache-control': 'public, max-age=7200',
29+
'cache-control': 'public, max-age=3600',
3030
'content-type': 'application/json',
3131
vary: 'Accept-Encoding'
3232
};

tests/integration/top-vaults/chart-data.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ test.describe('/top-vaults/chart-data', () => {
55
const response = await request.get('/top-vaults/chart-data');
66
expect(response.status()).toBe(200);
77
expect(response.headers()['content-type']).toContain('application/json');
8-
expect(response.headers()['cache-control']).toBe('public, max-age=7200');
8+
expect(response.headers()['cache-control']).toBe('public, max-age=3600');
99

1010
const data = await response.json();
1111
expect(data.vaults).toBeInstanceOf(Array);

0 commit comments

Comments
 (0)