reroute-js 0.43.4 → 0.43.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (186) hide show
  1. package/cli/bin.d.ts +1 -1
  2. package/cli/bin.js +74 -6
  3. package/cli/bin.js.map +3 -3
  4. package/cli/index.d.ts +1 -1
  5. package/cli/index.js +4 -4
  6. package/cli/index.js.map +1 -1
  7. package/cli/src/cli.d.ts +1 -1
  8. package/cli/src/commands/analyze.d.ts +1 -1
  9. package/cli/src/commands/build.d.ts +1 -1
  10. package/cli/src/commands/dev.d.ts +1 -1
  11. package/cli/src/commands/gen.d.ts +1 -1
  12. package/cli/src/commands/index.d.ts +1 -1
  13. package/cli/src/commands/init.d.ts +1 -1
  14. package/cli/src/commands/lib/assets.d.ts +1 -1
  15. package/cli/src/commands/lib/bundler.d.ts +1 -1
  16. package/cli/src/commands/lib/command.d.ts +1 -1
  17. package/cli/src/commands/lib/env.d.ts +1 -1
  18. package/cli/src/commands/lib/index.d.ts +1 -1
  19. package/cli/src/commands/lib/log.d.ts +1 -1
  20. package/cli/src/commands/lib/markdown/availability.d.ts +1 -1
  21. package/cli/src/commands/lib/markdown/index.d.ts +1 -1
  22. package/cli/src/commands/lib/markdown/processor.d.ts +1 -1
  23. package/cli/src/commands/lib/production.d.ts +1 -1
  24. package/cli/src/commands/lib/server.d.ts +1 -1
  25. package/cli/src/commands/lib/streaming/analyzer.d.ts +1 -1
  26. package/cli/src/commands/lib/streaming/suspense.d.ts +1 -1
  27. package/cli/src/commands/lib/tailwind.d.ts +1 -1
  28. package/cli/src/commands/lib/terminal-ui.d.ts +1 -1
  29. package/cli/src/commands/lib/version.d.ts +1 -1
  30. package/cli/src/commands/og.d.ts +1 -1
  31. package/cli/src/commands/start.d.ts +1 -1
  32. package/cli/src/index.d.ts +1 -1
  33. package/core/index.d.ts +1 -1
  34. package/core/index.js +70 -2
  35. package/core/index.js.map +3 -3
  36. package/core/src/bundler/hash.d.ts +1 -1
  37. package/core/src/bundler/index.d.ts +1 -1
  38. package/core/src/config.d.ts +1 -1
  39. package/core/src/content/discovery.d.ts +1 -1
  40. package/core/src/content/index.d.ts +1 -1
  41. package/core/src/content/metadata.d.ts +1 -1
  42. package/core/src/index.d.ts +1 -1
  43. package/core/src/llms/extractor.d.ts +1 -1
  44. package/core/src/llms/formatter.d.ts +1 -1
  45. package/core/src/llms/full-generator.d.ts +1 -1
  46. package/core/src/llms/index-generator.d.ts +1 -1
  47. package/core/src/llms/index.d.ts +1 -1
  48. package/core/src/og/discovery.d.ts +1 -1
  49. package/core/src/og/index.d.ts +1 -1
  50. package/core/src/og/meta.d.ts +1 -1
  51. package/core/src/og/render.d.ts +1 -1
  52. package/core/src/og/types.d.ts +1 -1
  53. package/core/src/robots/discovery.d.ts +1 -1
  54. package/core/src/robots/generator.d.ts +1 -1
  55. package/core/src/robots/index.d.ts +1 -1
  56. package/core/src/robots/policies.d.ts +1 -1
  57. package/core/src/rss/discovery.d.ts +1 -1
  58. package/core/src/rss/generator.d.ts +1 -1
  59. package/core/src/rss/index.d.ts +1 -1
  60. package/core/src/sitemap/discovery.d.ts +1 -1
  61. package/core/src/sitemap/generator.d.ts +1 -1
  62. package/core/src/sitemap/index.d.ts +1 -1
  63. package/core/src/ssr/index.d.ts +1 -1
  64. package/core/src/ssr/lib/cache.d.ts +53 -1
  65. package/core/src/ssr/lib/cache.d.ts.map +1 -1
  66. package/core/src/ssr/lib/collections.d.ts +1 -1
  67. package/core/src/ssr/lib/compression.d.ts +1 -1
  68. package/core/src/ssr/lib/compute/content.d.ts +1 -1
  69. package/core/src/ssr/lib/compute/index.d.ts +1 -1
  70. package/core/src/ssr/lib/compute/layouts.d.ts +1 -1
  71. package/core/src/ssr/lib/compute/routes.d.ts +1 -1
  72. package/core/src/ssr/lib/data.d.ts +1 -1
  73. package/core/src/ssr/lib/html.d.ts +1 -1
  74. package/core/src/ssr/lib/imports.d.ts +1 -1
  75. package/core/src/ssr/lib/index.d.ts +1 -1
  76. package/core/src/ssr/lib/layouts.d.ts +1 -1
  77. package/core/src/ssr/lib/metadata.d.ts +1 -1
  78. package/core/src/ssr/lib/mime.d.ts +1 -1
  79. package/core/src/ssr/lib/modules.d.ts +1 -1
  80. package/core/src/ssr/lib/path.d.ts +1 -1
  81. package/core/src/ssr/lib/preload.d.ts +1 -1
  82. package/core/src/ssr/lib/scripts/collections.d.ts +1 -1
  83. package/core/src/ssr/lib/scripts/data.d.ts +1 -1
  84. package/core/src/ssr/lib/scripts/escape.d.ts +1 -1
  85. package/core/src/ssr/lib/scripts/feeds.d.ts +1 -1
  86. package/core/src/ssr/lib/scripts/index.d.ts +1 -1
  87. package/core/src/ssr/lib/seed.d.ts +1 -1
  88. package/core/src/ssr/lib/serialize.d.ts +1 -1
  89. package/core/src/ssr/lib/setup.d.ts +1 -1
  90. package/core/src/ssr/lib/styles.d.ts +1 -1
  91. package/core/src/ssr/lib/template.d.ts +1 -1
  92. package/core/src/ssr/lib/types.d.ts +1 -1
  93. package/core/src/ssr/render.d.ts +1 -1
  94. package/core/src/ssr/stream.d.ts +1 -1
  95. package/elysia/index.d.ts +1 -1
  96. package/elysia/index.js +155 -106
  97. package/elysia/index.js.map +16 -16
  98. package/elysia/src/index.d.ts +1 -1
  99. package/elysia/src/libs/assets.d.ts +1 -1
  100. package/elysia/src/libs/cache.d.ts +1 -1
  101. package/elysia/src/libs/caching.d.ts +1 -1
  102. package/elysia/src/libs/http.d.ts +1 -1
  103. package/elysia/src/libs/image.d.ts +1 -1
  104. package/elysia/src/libs/index.d.ts +1 -1
  105. package/elysia/src/libs/llms.d.ts +1 -1
  106. package/elysia/src/libs/response.d.ts +1 -1
  107. package/elysia/src/libs/serving.d.ts +3 -3
  108. package/elysia/src/plugin.d.ts +1 -1
  109. package/elysia/src/plugin.d.ts.map +1 -1
  110. package/elysia/src/routes/artifacts.d.ts +3 -3
  111. package/elysia/src/routes/content.d.ts +3 -3
  112. package/elysia/src/routes/image.d.ts +1 -1
  113. package/elysia/src/routes/index.d.ts +1 -1
  114. package/elysia/src/routes/internal.d.ts +3 -3
  115. package/elysia/src/routes/internal.d.ts.map +1 -1
  116. package/elysia/src/routes/llms.d.ts +3 -3
  117. package/elysia/src/routes/llms.d.ts.map +1 -1
  118. package/elysia/src/routes/og.d.ts +3 -4
  119. package/elysia/src/routes/og.d.ts.map +1 -1
  120. package/elysia/src/routes/redirects.d.ts +1 -1
  121. package/elysia/src/routes/robots.d.ts +3 -4
  122. package/elysia/src/routes/robots.d.ts.map +1 -1
  123. package/elysia/src/routes/rss.d.ts +3 -4
  124. package/elysia/src/routes/rss.d.ts.map +1 -1
  125. package/elysia/src/routes/search.d.ts +1 -1
  126. package/elysia/src/routes/sitemap.d.ts +3 -4
  127. package/elysia/src/routes/sitemap.d.ts.map +1 -1
  128. package/elysia/src/routes/ssr.d.ts +1 -1
  129. package/elysia/src/routes/static.d.ts +3 -3
  130. package/elysia/src/types.d.ts +1 -1
  131. package/package.json +1 -1
  132. package/react/index.d.ts +1 -1
  133. package/react/index.js +2 -2
  134. package/react/index.js.map +1 -1
  135. package/react/src/components/ClientOnly.d.ts +1 -1
  136. package/react/src/components/ContentRoute.d.ts +1 -1
  137. package/react/src/components/Image.d.ts +1 -1
  138. package/react/src/components/LazyRoute.d.ts +1 -1
  139. package/react/src/components/Link.d.ts +1 -1
  140. package/react/src/components/Markdown.d.ts +1 -1
  141. package/react/src/components/Outlet.d.ts +1 -1
  142. package/react/src/components/index.d.ts +1 -1
  143. package/react/src/hooks/index.d.ts +1 -1
  144. package/react/src/hooks/useContent.d.ts +1 -1
  145. package/react/src/hooks/useData.d.ts +1 -1
  146. package/react/src/hooks/useFeed.d.ts +1 -1
  147. package/react/src/hooks/useLayoutData.d.ts +1 -1
  148. package/react/src/hooks/useLlms.d.ts +1 -1
  149. package/react/src/hooks/useNavigate.d.ts +1 -1
  150. package/react/src/hooks/useParams.d.ts +1 -1
  151. package/react/src/hooks/useRouter.d.ts +1 -1
  152. package/react/src/hooks/useSearch.d.ts +1 -1
  153. package/react/src/hooks/useSearchParams.d.ts +1 -1
  154. package/react/src/hooks/useToc.d.ts +1 -1
  155. package/react/src/index.d.ts +1 -1
  156. package/react/src/lib/collection.d.ts +1 -1
  157. package/react/src/lib/content.d.ts +1 -1
  158. package/react/src/lib/head.d.ts +1 -1
  159. package/react/src/lib/index.d.ts +1 -1
  160. package/react/src/lib/lazy-route.d.ts +1 -1
  161. package/react/src/lib/route-loader.d.ts +1 -1
  162. package/react/src/providers/ContentProvider.d.ts +1 -1
  163. package/react/src/providers/RerouteProvider.d.ts +1 -1
  164. package/react/src/providers/RouterProvider.d.ts +1 -1
  165. package/react/src/providers/index.d.ts +1 -1
  166. package/react/src/types/any.d.ts +1 -1
  167. package/react/src/types/index.d.ts +1 -1
  168. package/react/src/types/router.d.ts +1 -1
  169. package/telemetry/react.d.ts +1 -1
  170. package/telemetry/react.js +2 -2
  171. package/telemetry/react.js.map +1 -1
  172. package/telemetry/server.d.ts +1 -1
  173. package/telemetry/server.js +69 -2
  174. package/telemetry/server.js.map +3 -3
  175. package/telemetry/src/react/api.d.ts +1 -1
  176. package/telemetry/src/react/context.d.ts +1 -1
  177. package/telemetry/src/react/index.d.ts +1 -1
  178. package/telemetry/src/react/telemetry.d.ts +1 -1
  179. package/telemetry/src/server/context.d.ts +1 -1
  180. package/telemetry/src/server/headers/extractor.d.ts +1 -1
  181. package/telemetry/src/server/headers/index.d.ts +1 -1
  182. package/telemetry/src/server/headers/presets.d.ts +1 -1
  183. package/telemetry/src/server/index.d.ts +1 -1
  184. package/telemetry/src/server/instrumentation.d.ts +1 -1
  185. package/telemetry/src/server/plugin.d.ts +1 -1
  186. package/telemetry/src/server/sourcemap.d.ts +1 -1
package/elysia/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * reroute-js v0.43.4
2
+ * reroute-js v0.43.6
3
3
  *
4
4
  * @license MIT
5
5
  * @copyright 2026 stewones <hi@stewan.io>
@@ -491,6 +491,73 @@ class LRUCache {
491
491
  this.cache.clear();
492
492
  }
493
493
  }
494
+
495
+ class TTLCache {
496
+ cache = new Map;
497
+ maxSize;
498
+ defaultTtlMs;
499
+ cleanupInterval = null;
500
+ constructor(maxSize = 100, defaultTtlMs = 300000, cleanupIntervalMs = 60000) {
501
+ this.maxSize = maxSize;
502
+ this.defaultTtlMs = defaultTtlMs;
503
+ this.cleanupInterval = setInterval(() => {
504
+ this.cleanup();
505
+ }, cleanupIntervalMs);
506
+ if (this.cleanupInterval.unref) {
507
+ this.cleanupInterval.unref();
508
+ }
509
+ }
510
+ get(key) {
511
+ const entry = this.cache.get(key);
512
+ if (!entry)
513
+ return;
514
+ if (entry.exp <= Date.now()) {
515
+ this.cache.delete(key);
516
+ return;
517
+ }
518
+ return entry.value;
519
+ }
520
+ set(key, value, ttlMs) {
521
+ this.cache.delete(key);
522
+ if (this.cache.size >= this.maxSize) {
523
+ const firstKey = this.cache.keys().next().value;
524
+ if (firstKey !== undefined) {
525
+ this.cache.delete(firstKey);
526
+ }
527
+ }
528
+ this.cache.set(key, {
529
+ value,
530
+ exp: Date.now() + (ttlMs ?? this.defaultTtlMs)
531
+ });
532
+ }
533
+ has(key) {
534
+ return this.get(key) !== undefined;
535
+ }
536
+ delete(key) {
537
+ return this.cache.delete(key);
538
+ }
539
+ clear() {
540
+ this.cache.clear();
541
+ }
542
+ get size() {
543
+ return this.cache.size;
544
+ }
545
+ cleanup() {
546
+ const now = Date.now();
547
+ for (const [key, entry] of this.cache.entries()) {
548
+ if (entry.exp <= now) {
549
+ this.cache.delete(key);
550
+ }
551
+ }
552
+ }
553
+ destroy() {
554
+ if (this.cleanupInterval) {
555
+ clearInterval(this.cleanupInterval);
556
+ this.cleanupInterval = null;
557
+ }
558
+ this.clear();
559
+ }
560
+ }
494
561
  var getGlobalCache = () => {
495
562
  const g = globalThis;
496
563
  if (!g.__REROUTE_SSR_CACHE__) {
@@ -5338,6 +5405,7 @@ __export(exports_core, {
5338
5405
  allowAICrawlers: () => allowAICrawlers,
5339
5406
  acceptsGzip: () => acceptsGzip,
5340
5407
  acceptsBrotli: () => acceptsBrotli,
5408
+ TTLCache: () => TTLCache,
5341
5409
  SSRDataCache: () => SSRDataCache,
5342
5410
  SEARCH_CRAWLERS: () => SEARCH_CRAWLERS,
5343
5411
  LRUCache: () => LRUCache,
@@ -6084,15 +6152,13 @@ function registerInternalRoutes(app, opts) {
6084
6152
  async function handleKeyRequest(pathname, dataKey, headers2) {
6085
6153
  const { computeSSRData: computeSSRData2 } = await Promise.resolve().then(() => (init_core(), exports_core));
6086
6154
  const cacheKey = `${pathname}:promises`;
6087
- let promiseData = maxAge > 0 ? dataCache?.get(cacheKey) : undefined;
6155
+ let promiseData = dataCache?.get(cacheKey);
6088
6156
  const promiseDataCached = promiseData !== undefined;
6089
6157
  if (!promiseData) {
6090
6158
  const sp = extractSearchParams(pathname);
6091
6159
  const { data } = await computeSSRData2(pathname, clientDir, cwd, isWatchMode, { streaming: true, maxAge }, sp);
6092
6160
  promiseData = data;
6093
- if (maxAge > 0) {
6094
- dataCache?.set(cacheKey, promiseData);
6095
- }
6161
+ dataCache?.set(cacheKey, promiseData);
6096
6162
  }
6097
6163
  if (promiseData && typeof promiseData === "object") {
6098
6164
  const value = promiseData[dataKey];
@@ -6396,18 +6462,6 @@ function registerLiveReloadRoutes(app, state) {
6396
6462
  init_core();
6397
6463
  import { NotFoundError as NotFoundError5 } from "elysia";
6398
6464
 
6399
- // packages/elysia/src/libs/caching.ts
6400
- function toTTL(seconds) {
6401
- return seconds * 1000;
6402
- }
6403
- function isValid(entry) {
6404
- return entry !== undefined && entry.exp > Date.now();
6405
- }
6406
- function getIfValid(cache2, key) {
6407
- const entry = cache2.get(key);
6408
- return isValid(entry) ? entry : undefined;
6409
- }
6410
-
6411
6465
  // packages/elysia/src/libs/llms.ts
6412
6466
  function capitalize(str) {
6413
6467
  return str.charAt(0).toUpperCase() + str.slice(1);
@@ -6541,9 +6595,9 @@ function registerLLMsRoutes(app, options) {
6541
6595
  llmsConfig,
6542
6596
  collections: collections2
6543
6597
  } = options;
6544
- const llmsCache = new Map;
6545
6598
  const defaults = calculateLlmsDefaults(llmsConfig, maxAge);
6546
6599
  const { ttlMs, ttlMsFull, baseUrl } = defaults;
6600
+ const llmsCache = new TTLCache(100, ttlMs);
6547
6601
  const availableLlms = [];
6548
6602
  const responseOpts = {
6549
6603
  maxAge: defaults.maxAge,
@@ -6558,9 +6612,9 @@ function registerLLMsRoutes(app, options) {
6558
6612
  app.get("/llms.txt", async () => {
6559
6613
  const cacheKey = buildLlmsIndexCacheKey();
6560
6614
  try {
6561
- const cached = getIfValid(llmsCache, cacheKey);
6615
+ const cached = llmsCache.get(cacheKey);
6562
6616
  if (cached) {
6563
- return textResponse(cached.content, {
6617
+ return textResponse(cached, {
6564
6618
  ...responseOpts,
6565
6619
  cacheStatus: "HIT"
6566
6620
  });
@@ -6572,7 +6626,7 @@ function registerLLMsRoutes(app, options) {
6572
6626
  isWatchMode,
6573
6627
  llmsConfig
6574
6628
  });
6575
- llmsCache.set(cacheKey, { content: content2, exp: Date.now() + ttlMs });
6629
+ llmsCache.set(cacheKey, content2);
6576
6630
  return textResponse(content2, { ...responseOpts, cacheStatus: "MISS" });
6577
6631
  } catch (error) {
6578
6632
  console.error("[reroute/llms] Failed to generate index:", error);
@@ -6584,9 +6638,9 @@ function registerLLMsRoutes(app, options) {
6584
6638
  app.get("/llms-full.txt", async () => {
6585
6639
  const cacheKey = buildLlmsFullCacheKey();
6586
6640
  try {
6587
- const cached = getIfValid(llmsCache, cacheKey);
6641
+ const cached = llmsCache.get(cacheKey);
6588
6642
  if (cached) {
6589
- return textResponse(cached.content, {
6643
+ return textResponse(cached, {
6590
6644
  ...responseOptsFull,
6591
6645
  cacheStatus: "HIT"
6592
6646
  });
@@ -6604,7 +6658,7 @@ function registerLLMsRoutes(app, options) {
6604
6658
  llmsConfig
6605
6659
  });
6606
6660
  console.log(`[reroute/llms] Generated llms-full.txt: ${stats.itemCount} items, ${formatByteSize(stats.byteSize)}MB`);
6607
- llmsCache.set(cacheKey, { content: content2, exp: Date.now() + ttlMsFull });
6661
+ llmsCache.set(cacheKey, content2, ttlMsFull);
6608
6662
  return textResponse(content2, {
6609
6663
  ...responseOptsFull,
6610
6664
  cacheStatus: "MISS"
@@ -6624,9 +6678,9 @@ function registerLLMsRoutes(app, options) {
6624
6678
  app.get(`/${collection}/llms.txt`, async () => {
6625
6679
  const cacheKey = buildLlmsIndexCacheKey(collection);
6626
6680
  try {
6627
- const cached = getIfValid(llmsCache, cacheKey);
6681
+ const cached = llmsCache.get(cacheKey);
6628
6682
  if (cached) {
6629
- return textResponse(cached.content, {
6683
+ return textResponse(cached, {
6630
6684
  ...responseOpts,
6631
6685
  cacheStatus: "HIT"
6632
6686
  });
@@ -6642,7 +6696,7 @@ function registerLLMsRoutes(app, options) {
6642
6696
  siteDescription: meta.description
6643
6697
  }
6644
6698
  });
6645
- llmsCache.set(cacheKey, { content: content2, exp: Date.now() + ttlMs });
6699
+ llmsCache.set(cacheKey, content2);
6646
6700
  return textResponse(content2, {
6647
6701
  ...responseOpts,
6648
6702
  cacheStatus: "MISS"
@@ -6657,9 +6711,9 @@ function registerLLMsRoutes(app, options) {
6657
6711
  app.get(`/${collection}/llms-full.txt`, async () => {
6658
6712
  const cacheKey = buildLlmsFullCacheKey(collection);
6659
6713
  try {
6660
- const cached = getIfValid(llmsCache, cacheKey);
6714
+ const cached = llmsCache.get(cacheKey);
6661
6715
  if (cached) {
6662
- return textResponse(cached.content, {
6716
+ return textResponse(cached, {
6663
6717
  ...responseOptsFull,
6664
6718
  cacheStatus: "HIT"
6665
6719
  });
@@ -6681,7 +6735,7 @@ function registerLLMsRoutes(app, options) {
6681
6735
  }
6682
6736
  });
6683
6737
  console.log(`[reroute/llms] Generated ${collection}/llms-full.txt: ${stats.itemCount} items, ${formatByteSize(stats.byteSize)}MB`);
6684
- llmsCache.set(cacheKey, { content: content2, exp: Date.now() + ttlMsFull });
6738
+ llmsCache.set(cacheKey, content2, ttlMsFull);
6685
6739
  return textResponse(content2, {
6686
6740
  ...responseOptsFull,
6687
6741
  cacheStatus: "MISS"
@@ -6696,12 +6750,12 @@ function registerLLMsRoutes(app, options) {
6696
6750
  if (shouldEnableContentNegotiation(llmsConfig)) {
6697
6751
  async function handleLLMRequest(pathname, format, acceptEncoding) {
6698
6752
  const cacheKey = buildLlmsCacheKey(pathname, format, acceptEncoding);
6699
- const cached = getIfValid(llmsCache, cacheKey);
6753
+ const cached = llmsCache.get(cacheKey);
6700
6754
  if (cached) {
6701
- return format === "md" ? markdownResponse(cached.content, {
6755
+ return format === "md" ? markdownResponse(cached, {
6702
6756
  ...responseOpts,
6703
6757
  cacheStatus: "HIT"
6704
- }) : textResponse(cached.content, {
6758
+ }) : textResponse(cached, {
6705
6759
  ...responseOpts,
6706
6760
  extraHeaders: { Vary: "Accept" },
6707
6761
  cacheStatus: "HIT"
@@ -6718,7 +6772,7 @@ function registerLLMsRoutes(app, options) {
6718
6772
  format,
6719
6773
  llmsConfig
6720
6774
  });
6721
- llmsCache.set(cacheKey, { content: content2, exp: Date.now() + ttlMs });
6775
+ llmsCache.set(cacheKey, content2);
6722
6776
  return format === "md" ? markdownResponse(content2, { ...responseOpts, cacheStatus: "MISS" }) : textResponse(content2, {
6723
6777
  ...responseOpts,
6724
6778
  extraHeaders: { Vary: "Accept" },
@@ -6962,14 +7016,12 @@ function registerOGRoutes(app, options) {
6962
7016
  return pathname;
6963
7017
  }
6964
7018
  function checkOgCache(pathname, set) {
6965
- if (maxAge > 0) {
6966
- const cached = getIfValid(ogCache, pathname);
6967
- if (cached) {
6968
- set.headers["content-type"] = "image/png";
6969
- set.headers["cache-control"] = `public, max-age=${maxAge}`;
6970
- set.headers["Reroute-Cache"] = "HIT";
6971
- return new Response(cached.buffer);
6972
- }
7019
+ const cached = ogCache.get(pathname);
7020
+ if (cached) {
7021
+ set.headers["content-type"] = "image/png";
7022
+ set.headers["cache-control"] = `public, max-age=${maxAge}`;
7023
+ set.headers["Reroute-Cache"] = "HIT";
7024
+ return new Response(cached);
6973
7025
  }
6974
7026
  return;
6975
7027
  }
@@ -7040,9 +7092,7 @@ function registerOGRoutes(app, options) {
7040
7092
  siteName: routeOgImage?.siteName ?? ogConfig2.siteName,
7041
7093
  baseUrl: ogConfig2.baseUrl
7042
7094
  }, { width: width2, height: height2, fonts });
7043
- if (maxAge > 0) {
7044
- ogCache.set(pathname, { buffer, exp: Date.now() + maxAge * 1000 });
7045
- }
7095
+ ogCache.set(pathname, buffer);
7046
7096
  }
7047
7097
  app.get("/__reroute_og/*", async ({ request, set }) => {
7048
7098
  try {
@@ -7204,16 +7254,15 @@ function registerRobotsRoute(app, options) {
7204
7254
  sitemapEnabled,
7205
7255
  redirects
7206
7256
  } = options;
7207
- const ttlMs = toTTL(maxAge);
7208
7257
  app.get("/robots.txt", async () => {
7209
7258
  try {
7210
- const cached = getIfValid(robotsCache, "robots:main");
7259
+ const cached = robotsCache.get("robots:main");
7211
7260
  if (cached) {
7212
- return textResponse(cached.txt, { maxAge, cacheStatus: "HIT" });
7261
+ return textResponse(cached, { maxAge, cacheStatus: "HIT" });
7213
7262
  }
7214
7263
  const discovery5 = await discoverRobotsData(cwd, isWatchMode, robotsConfig, sitemapConfig, redirects);
7215
7264
  const txt = generateRobots(discovery5, robotsConfig, sitemapEnabled);
7216
- robotsCache.set("robots:main", { txt, exp: Date.now() + ttlMs });
7265
+ robotsCache.set("robots:main", txt);
7217
7266
  return textResponse(txt, { maxAge, cacheStatus: "MISS" });
7218
7267
  } catch (error) {
7219
7268
  console.error("[reroute] Failed to generate robots.txt:", error);
@@ -7226,21 +7275,24 @@ function registerRobotsRoute(app, options) {
7226
7275
  // packages/elysia/src/routes/rss.ts
7227
7276
  init_core();
7228
7277
  import { NotFoundError as NotFoundError8 } from "elysia";
7229
- var rssDiscoveryCache = new LRUCache(1);
7278
+
7279
+ // packages/elysia/src/libs/caching.ts
7280
+ function toTTL(seconds) {
7281
+ return seconds * 1000;
7282
+ }
7283
+
7284
+ // packages/elysia/src/routes/rss.ts
7285
+ var rssDiscoveryCache = new TTLCache(1, 5 * 60 * 1000);
7230
7286
  async function getOrDiscoverRSSData(cwd, collections2, baseUrl, isWatchMode, rssConfig) {
7231
7287
  if (isWatchMode) {
7232
7288
  return discoverRSSData(cwd, collections2, baseUrl, isWatchMode, rssConfig);
7233
7289
  }
7234
7290
  const cacheKey = "rss:discovery";
7235
7291
  const cached = rssDiscoveryCache.get(cacheKey);
7236
- if (cached && cached.exp > Date.now()) {
7237
- return cached.discovery;
7238
- }
7292
+ if (cached)
7293
+ return cached;
7239
7294
  const discovery5 = await discoverRSSData(cwd, collections2, baseUrl, isWatchMode, rssConfig);
7240
- rssDiscoveryCache.set(cacheKey, {
7241
- discovery: discovery5,
7242
- exp: Date.now() + 5 * 60 * 1000
7243
- });
7295
+ rssDiscoveryCache.set(cacheKey, discovery5);
7244
7296
  return discovery5;
7245
7297
  }
7246
7298
  function createFeedTitle(configTitle, name) {
@@ -7266,12 +7318,12 @@ async function discoverSSRRoutes(cwd, isWatchMode) {
7266
7318
  return [];
7267
7319
  }
7268
7320
  }
7269
- async function registerMainFeedRoute(app, cwd, collections2, baseUrl, isWatchMode, rssCache, format, limit, maxAge, ttlMs, feedTitle, feedDescription, rssConfig) {
7321
+ async function registerMainFeedRoute(app, cwd, collections2, baseUrl, isWatchMode, rssCache, format, limit, maxAge, _ttlMs, feedTitle, feedDescription, rssConfig) {
7270
7322
  app.get("/feed.xml", async () => {
7271
7323
  try {
7272
- const cached = getIfValid(rssCache, "rss:main");
7324
+ const cached = rssCache.get("rss:main");
7273
7325
  if (cached) {
7274
- return feedResponse(cached.xml, format, { maxAge, cacheStatus: "HIT" });
7326
+ return feedResponse(cached, format, { maxAge, cacheStatus: "HIT" });
7275
7327
  }
7276
7328
  const discovery5 = await getOrDiscoverRSSData(cwd, collections2, baseUrl, isWatchMode, rssConfig);
7277
7329
  const allItems = [
@@ -7291,7 +7343,7 @@ async function registerMainFeedRoute(app, cwd, collections2, baseUrl, isWatchMod
7291
7343
  items: allItems
7292
7344
  };
7293
7345
  const xml = generateFeed(feed, { format, limit });
7294
- rssCache.set("rss:main", { xml, exp: Date.now() + ttlMs });
7346
+ rssCache.set("rss:main", xml);
7295
7347
  return feedResponse(xml, format, { maxAge, cacheStatus: "MISS" });
7296
7348
  } catch (error) {
7297
7349
  console.error("[reroute] Failed to generate main feed:", error);
@@ -7305,9 +7357,9 @@ function registerCollectionFeedRoutes(app, collections2, options) {
7305
7357
  app.get(`/${collection}/feed.xml`, async () => {
7306
7358
  const cacheKey = `rss:${collection}`;
7307
7359
  try {
7308
- const cached = getIfValid(options.rssCache, cacheKey);
7360
+ const cached = options.rssCache.get(cacheKey);
7309
7361
  if (cached) {
7310
- return feedResponse(cached.xml, options.format, {
7362
+ return feedResponse(cached, options.format, {
7311
7363
  maxAge: options.maxAge,
7312
7364
  cacheStatus: "HIT"
7313
7365
  });
@@ -7326,10 +7378,7 @@ function registerCollectionFeedRoutes(app, collections2, options) {
7326
7378
  format: options.format,
7327
7379
  limit: options.limit
7328
7380
  });
7329
- options.rssCache.set(cacheKey, {
7330
- xml,
7331
- exp: Date.now() + options.ttlMs
7332
- });
7381
+ options.rssCache.set(cacheKey, xml);
7333
7382
  return feedResponse(xml, options.format, {
7334
7383
  maxAge: options.maxAge,
7335
7384
  cacheStatus: "MISS"
@@ -7364,9 +7413,9 @@ async function discoverRoutesWithFeeds(ssrDataRoutes, collections2, options) {
7364
7413
  async function generateSSRDataFeed(route, options) {
7365
7414
  const routeName = route.pattern.replace(/^\//, "") || "index";
7366
7415
  const cacheKey = `rss:${routeName}`;
7367
- const cached = getIfValid(options.rssCache, cacheKey);
7416
+ const cached = options.rssCache.get(cacheKey);
7368
7417
  if (cached) {
7369
- return feedResponse(cached.xml, options.format, {
7418
+ return feedResponse(cached, options.format, {
7370
7419
  maxAge: options.maxAge,
7371
7420
  cacheStatus: "HIT"
7372
7421
  });
@@ -7388,10 +7437,7 @@ async function generateSSRDataFeed(route, options) {
7388
7437
  format: options.format,
7389
7438
  limit: options.limit
7390
7439
  });
7391
- options.rssCache.set(cacheKey, {
7392
- xml,
7393
- exp: Date.now() + options.ttlMs
7394
- });
7440
+ options.rssCache.set(cacheKey, xml);
7395
7441
  return feedResponse(xml, options.format, {
7396
7442
  maxAge: options.maxAge,
7397
7443
  cacheStatus: "MISS"
@@ -7598,21 +7644,17 @@ function registerSearchRoute(app, cwd, directive, maxAge, searchConfig) {
7598
7644
  // packages/elysia/src/routes/sitemap.ts
7599
7645
  init_core();
7600
7646
  import { NotFoundError as NotFoundError9 } from "elysia";
7601
- var sitemapDiscoveryCache = new LRUCache(1);
7647
+ var sitemapDiscoveryCache = new TTLCache(1, 5 * 60 * 1000);
7602
7648
  async function getOrDiscoverSitemapData(cwd, collections2, baseUrl, isWatchMode, sitemapConfig) {
7603
7649
  if (isWatchMode) {
7604
7650
  return discoverSitemapData(cwd, collections2, baseUrl, isWatchMode, sitemapConfig);
7605
7651
  }
7606
7652
  const cacheKey = "sitemap:discovery";
7607
7653
  const cached = sitemapDiscoveryCache.get(cacheKey);
7608
- if (cached && cached.exp > Date.now()) {
7609
- return cached.discovery;
7610
- }
7654
+ if (cached)
7655
+ return cached;
7611
7656
  const discovery5 = await discoverSitemapData(cwd, collections2, baseUrl, isWatchMode, sitemapConfig);
7612
- sitemapDiscoveryCache.set(cacheKey, {
7613
- discovery: discovery5,
7614
- exp: Date.now() + 5 * 60 * 1000
7615
- });
7657
+ sitemapDiscoveryCache.set(cacheKey, discovery5);
7616
7658
  return discovery5;
7617
7659
  }
7618
7660
  async function generateAndCacheSitemap(options, _ttlMs) {
@@ -7635,23 +7677,17 @@ function registerSitemapRoutes(app, options) {
7635
7677
  const ttlMs = toTTL(maxAge);
7636
7678
  app.get("/sitemap.xml", async () => {
7637
7679
  try {
7638
- const cached = getIfValid(sitemapCache, "sitemap:main");
7680
+ const cached = sitemapCache.get("sitemap:main");
7639
7681
  if (cached) {
7640
- return xmlResponse(cached.xml, { maxAge, cacheStatus: "HIT" });
7682
+ return xmlResponse(cached, { maxAge, cacheStatus: "HIT" });
7641
7683
  }
7642
7684
  const result = await generateAndCacheSitemap(options, ttlMs);
7643
7685
  if (result.needsIndex) {
7644
7686
  for (const page of result.pages) {
7645
- sitemapCache.set(`sitemap:${page.filename}`, {
7646
- xml: page.xml,
7647
- exp: Date.now() + ttlMs
7648
- });
7687
+ sitemapCache.set(`sitemap:${page.filename}`, page.xml);
7649
7688
  }
7650
7689
  }
7651
- sitemapCache.set("sitemap:main", {
7652
- xml: result.xml,
7653
- exp: Date.now() + ttlMs
7654
- });
7690
+ sitemapCache.set("sitemap:main", result.xml);
7655
7691
  return xmlResponse(result.xml, { maxAge, cacheStatus: "MISS" });
7656
7692
  } catch (error) {
7657
7693
  console.error("[reroute] Failed to generate sitemap:", error);
@@ -7667,19 +7703,16 @@ function registerSitemapRoutes(app, options) {
7667
7703
  const filename = `sitemap-${pageMatch[1]}.xml`;
7668
7704
  const cacheKey = `sitemap:${filename}`;
7669
7705
  try {
7670
- const cached = getIfValid(sitemapCache, cacheKey);
7706
+ const cached = sitemapCache.get(cacheKey);
7671
7707
  if (cached) {
7672
- return xmlResponse(cached.xml, { maxAge, cacheStatus: "HIT" });
7708
+ return xmlResponse(cached, { maxAge, cacheStatus: "HIT" });
7673
7709
  }
7674
7710
  const result = await generateAndCacheSitemap(options, ttlMs);
7675
7711
  const pageData = result.pages.find((p) => p.filename === filename);
7676
7712
  if (!pageData) {
7677
7713
  throw new NotFoundError9;
7678
7714
  }
7679
- sitemapCache.set(cacheKey, {
7680
- xml: pageData.xml,
7681
- exp: Date.now() + ttlMs
7682
- });
7715
+ sitemapCache.set(cacheKey, pageData.xml);
7683
7716
  return xmlResponse(pageData.xml, { maxAge, cacheStatus: "MISS" });
7684
7717
  } catch (error) {
7685
7718
  if (error instanceof NotFoundError9)
@@ -8321,13 +8354,14 @@ var reroute = () => async (app) => {
8321
8354
  const llmsEnabled = llmsConfig?.enabled === true;
8322
8355
  const robotsConfig = globalConfig.robots;
8323
8356
  const robotsEnabled = robotsConfig?.enabled === true;
8324
- const fileCache = new LRUCache(100);
8325
- const dataCache = new LRUCache(100);
8326
- const collectionCache = new LRUCache(50);
8327
- const sitemapCache = new LRUCache(20);
8328
- const rssCache = new LRUCache(20);
8329
- const ogCache = new LRUCache(100);
8330
- const robotsCache = new LRUCache(10);
8357
+ const serverTtlMs = serverMaxAge * 1000;
8358
+ const fileCache = new TTLCache(100, serverTtlMs);
8359
+ const dataCache = new TTLCache(100, serverTtlMs);
8360
+ const collectionCache = new TTLCache(50, serverTtlMs);
8361
+ const sitemapCache = new TTLCache(20, serverTtlMs);
8362
+ const rssCache = new TTLCache(20, serverTtlMs);
8363
+ const ogCache = new TTLCache(100, serverTtlMs);
8364
+ const robotsCache = new TTLCache(10, serverTtlMs);
8331
8365
  const liveReloadState = {
8332
8366
  clients: new Set,
8333
8367
  pendingReload: false
@@ -8411,7 +8445,22 @@ var reroute = () => async (app) => {
8411
8445
  const startupCollections = await loadCollections2(cwd, isWatchMode);
8412
8446
  const startupTailwindCSS = await inlineTailwindCSS2(clientDir, false, isWatchMode);
8413
8447
  const startupIndexHtml = await loadIndexHtml2(clientDir);
8414
- const getCollections = isWatchMode ? () => loadCollections2(cwd, isWatchMode) : async () => startupCollections;
8448
+ const collectionsTtlMs = serverMaxAge * 1000;
8449
+ let collectionsCache = serverCacheEnabled ? { data: startupCollections, exp: Date.now() + collectionsTtlMs } : null;
8450
+ const getCollections = isWatchMode ? () => loadCollections2(cwd, isWatchMode) : async () => {
8451
+ if (!serverCacheEnabled) {
8452
+ return loadCollections2(cwd, isWatchMode);
8453
+ }
8454
+ if (collectionsCache && collectionsCache.exp > Date.now()) {
8455
+ return collectionsCache.data;
8456
+ }
8457
+ const fresh = await loadCollections2(cwd, isWatchMode);
8458
+ collectionsCache = {
8459
+ data: fresh,
8460
+ exp: Date.now() + collectionsTtlMs
8461
+ };
8462
+ return fresh;
8463
+ };
8415
8464
  const getTailwindCSS = isWatchMode ? () => inlineTailwindCSS2(clientDir, false, isWatchMode) : async () => startupTailwindCSS;
8416
8465
  const getIndexHtml = isWatchMode ? () => loadIndexHtml2(clientDir) : async () => startupIndexHtml;
8417
8466
  if (globalConfig.redirects && globalConfig.redirects.length > 0) {
@@ -8601,4 +8650,4 @@ export {
8601
8650
  reroute
8602
8651
  };
8603
8652
 
8604
- //# debugId=794066AD38470A5564756E2164756E21
8653
+ //# debugId=F52BE988669929F264756E2164756E21