Commit 1ed4d98
committed
feat(cache): add in-memory LRU cache for GET /api/campaigns with 5-second TTL
Adds campaignCache.ts backed by lru-cache to avoid SQLite on every
campaign-list request. Cache hit returns the pre-serialised JSON body
directly, skipping the query entirely. All write paths (create, pledge,
reconcile, claim, refund) call invalidateCampaignCache() so stale data
is never served past the current request. Cache-Control: max-age=5 and
X-Cache: HIT/MISS headers are set on every response. Max cache size is
configurable via CAMPAIGN_CACHE_MAX_SIZE env var (default 100).
Closes #2161 parent 1beddc1 commit 1ed4d98
5 files changed
Lines changed: 136 additions & 1 deletion
File tree
- backend
- src
- services
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
| 13 | + | |
13 | 14 | | |
14 | 15 | | |
15 | 16 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
58 | 58 | | |
59 | 59 | | |
60 | 60 | | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
61 | 67 | | |
62 | 68 | | |
63 | 69 | | |
| |||
270 | 276 | | |
271 | 277 | | |
272 | 278 | | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
273 | 295 | | |
274 | 296 | | |
275 | 297 | | |
| |||
299 | 321 | | |
300 | 322 | | |
301 | 323 | | |
302 | | - | |
| 324 | + | |
303 | 325 | | |
304 | 326 | | |
305 | 327 | | |
| |||
308 | 330 | | |
309 | 331 | | |
310 | 332 | | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
311 | 340 | | |
312 | 341 | | |
313 | 342 | | |
| |||
382 | 411 | | |
383 | 412 | | |
384 | 413 | | |
| 414 | + | |
385 | 415 | | |
386 | 416 | | |
387 | 417 | | |
| |||
400 | 430 | | |
401 | 431 | | |
402 | 432 | | |
| 433 | + | |
403 | 434 | | |
404 | 435 | | |
405 | 436 | | |
| |||
419 | 450 | | |
420 | 451 | | |
421 | 452 | | |
| 453 | + | |
422 | 454 | | |
423 | 455 | | |
424 | 456 | | |
| |||
447 | 479 | | |
448 | 480 | | |
449 | 481 | | |
| 482 | + | |
450 | 483 | | |
451 | 484 | | |
452 | 485 | | |
| |||
476 | 509 | | |
477 | 510 | | |
478 | 511 | | |
| 512 | + | |
479 | 513 | | |
480 | 514 | | |
481 | 515 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
0 commit comments