reroute-js 0.43.5 → 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 +158 -127
  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 -4
  115. package/elysia/src/routes/internal.d.ts.map +1 -1
  116. package/elysia/src/routes/llms.d.ts +3 -4
  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.5
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,
@@ -6081,43 +6149,23 @@ function registerInternalRoutes(app, opts) {
6081
6149
  }
6082
6150
  });
6083
6151
  });
6084
- const cacheTtlMs = maxAge * 1000;
6085
- function getCacheEntry(key) {
6086
- if (maxAge <= 0)
6087
- return;
6088
- const entry = dataCache?.get(key);
6089
- if (!entry)
6090
- return;
6091
- if (entry.exp <= Date.now()) {
6092
- return;
6093
- }
6094
- return entry.data;
6095
- }
6096
- function setCacheEntry(key, data) {
6097
- if (maxAge <= 0)
6098
- return;
6099
- dataCache?.set(key, {
6100
- data,
6101
- exp: Date.now() + cacheTtlMs
6102
- });
6103
- }
6104
6152
  async function handleKeyRequest(pathname, dataKey, headers2) {
6105
6153
  const { computeSSRData: computeSSRData2 } = await Promise.resolve().then(() => (init_core(), exports_core));
6106
6154
  const cacheKey = `${pathname}:promises`;
6107
- let promiseData = getCacheEntry(cacheKey);
6155
+ let promiseData = dataCache?.get(cacheKey);
6108
6156
  const promiseDataCached = promiseData !== undefined;
6109
6157
  if (!promiseData) {
6110
6158
  const sp = extractSearchParams(pathname);
6111
6159
  const { data } = await computeSSRData2(pathname, clientDir, cwd, isWatchMode, { streaming: true, maxAge }, sp);
6112
6160
  promiseData = data;
6113
- setCacheEntry(cacheKey, promiseData);
6161
+ dataCache?.set(cacheKey, promiseData);
6114
6162
  }
6115
6163
  if (promiseData && typeof promiseData === "object") {
6116
6164
  const value = promiseData[dataKey];
6117
6165
  if (value instanceof Promise) {
6118
6166
  const resolved = await value;
6119
6167
  const resolvedCacheKey = `${pathname}:${dataKey}:resolved`;
6120
- setCacheEntry(resolvedCacheKey, resolved);
6168
+ dataCache?.set(resolvedCacheKey, resolved);
6121
6169
  return jsonWithCache({ data: resolved }, dataCacheControl || "no-cache", headers2, promiseDataCached ? "HIT" : "MISS");
6122
6170
  }
6123
6171
  if (value !== undefined) {
@@ -6129,7 +6177,7 @@ function registerInternalRoutes(app, opts) {
6129
6177
  async function handleFullDataRequest(pathname) {
6130
6178
  const { computeSSRData: computeSSRData2 } = await Promise.resolve().then(() => (init_core(), exports_core));
6131
6179
  const cacheKey = `${pathname}:streaming`;
6132
- let data = getCacheEntry(cacheKey);
6180
+ let data = dataCache?.get(cacheKey);
6133
6181
  const cacheHit = data !== undefined;
6134
6182
  if (data === undefined) {
6135
6183
  const sp = extractSearchParams(pathname);
@@ -6140,7 +6188,7 @@ function registerInternalRoutes(app, opts) {
6140
6188
  console.error("[__reroute_data] Error computing data:", error);
6141
6189
  data = null;
6142
6190
  }
6143
- setCacheEntry(cacheKey, data);
6191
+ dataCache?.set(cacheKey, data);
6144
6192
  }
6145
6193
  return { data, cacheHit };
6146
6194
  }
@@ -6414,18 +6462,6 @@ function registerLiveReloadRoutes(app, state) {
6414
6462
  init_core();
6415
6463
  import { NotFoundError as NotFoundError5 } from "elysia";
6416
6464
 
6417
- // packages/elysia/src/libs/caching.ts
6418
- function toTTL(seconds) {
6419
- return seconds * 1000;
6420
- }
6421
- function isValid(entry) {
6422
- return entry !== undefined && entry.exp > Date.now();
6423
- }
6424
- function getIfValid(cache2, key) {
6425
- const entry = cache2.get(key);
6426
- return isValid(entry) ? entry : undefined;
6427
- }
6428
-
6429
6465
  // packages/elysia/src/libs/llms.ts
6430
6466
  function capitalize(str) {
6431
6467
  return str.charAt(0).toUpperCase() + str.slice(1);
@@ -6559,9 +6595,9 @@ function registerLLMsRoutes(app, options) {
6559
6595
  llmsConfig,
6560
6596
  collections: collections2
6561
6597
  } = options;
6562
- const llmsCache = new Map;
6563
6598
  const defaults = calculateLlmsDefaults(llmsConfig, maxAge);
6564
6599
  const { ttlMs, ttlMsFull, baseUrl } = defaults;
6600
+ const llmsCache = new TTLCache(100, ttlMs);
6565
6601
  const availableLlms = [];
6566
6602
  const responseOpts = {
6567
6603
  maxAge: defaults.maxAge,
@@ -6576,9 +6612,9 @@ function registerLLMsRoutes(app, options) {
6576
6612
  app.get("/llms.txt", async () => {
6577
6613
  const cacheKey = buildLlmsIndexCacheKey();
6578
6614
  try {
6579
- const cached = getIfValid(llmsCache, cacheKey);
6615
+ const cached = llmsCache.get(cacheKey);
6580
6616
  if (cached) {
6581
- return textResponse(cached.content, {
6617
+ return textResponse(cached, {
6582
6618
  ...responseOpts,
6583
6619
  cacheStatus: "HIT"
6584
6620
  });
@@ -6590,7 +6626,7 @@ function registerLLMsRoutes(app, options) {
6590
6626
  isWatchMode,
6591
6627
  llmsConfig
6592
6628
  });
6593
- llmsCache.set(cacheKey, { content: content2, exp: Date.now() + ttlMs });
6629
+ llmsCache.set(cacheKey, content2);
6594
6630
  return textResponse(content2, { ...responseOpts, cacheStatus: "MISS" });
6595
6631
  } catch (error) {
6596
6632
  console.error("[reroute/llms] Failed to generate index:", error);
@@ -6602,9 +6638,9 @@ function registerLLMsRoutes(app, options) {
6602
6638
  app.get("/llms-full.txt", async () => {
6603
6639
  const cacheKey = buildLlmsFullCacheKey();
6604
6640
  try {
6605
- const cached = getIfValid(llmsCache, cacheKey);
6641
+ const cached = llmsCache.get(cacheKey);
6606
6642
  if (cached) {
6607
- return textResponse(cached.content, {
6643
+ return textResponse(cached, {
6608
6644
  ...responseOptsFull,
6609
6645
  cacheStatus: "HIT"
6610
6646
  });
@@ -6622,7 +6658,7 @@ function registerLLMsRoutes(app, options) {
6622
6658
  llmsConfig
6623
6659
  });
6624
6660
  console.log(`[reroute/llms] Generated llms-full.txt: ${stats.itemCount} items, ${formatByteSize(stats.byteSize)}MB`);
6625
- llmsCache.set(cacheKey, { content: content2, exp: Date.now() + ttlMsFull });
6661
+ llmsCache.set(cacheKey, content2, ttlMsFull);
6626
6662
  return textResponse(content2, {
6627
6663
  ...responseOptsFull,
6628
6664
  cacheStatus: "MISS"
@@ -6642,9 +6678,9 @@ function registerLLMsRoutes(app, options) {
6642
6678
  app.get(`/${collection}/llms.txt`, async () => {
6643
6679
  const cacheKey = buildLlmsIndexCacheKey(collection);
6644
6680
  try {
6645
- const cached = getIfValid(llmsCache, cacheKey);
6681
+ const cached = llmsCache.get(cacheKey);
6646
6682
  if (cached) {
6647
- return textResponse(cached.content, {
6683
+ return textResponse(cached, {
6648
6684
  ...responseOpts,
6649
6685
  cacheStatus: "HIT"
6650
6686
  });
@@ -6660,7 +6696,7 @@ function registerLLMsRoutes(app, options) {
6660
6696
  siteDescription: meta.description
6661
6697
  }
6662
6698
  });
6663
- llmsCache.set(cacheKey, { content: content2, exp: Date.now() + ttlMs });
6699
+ llmsCache.set(cacheKey, content2);
6664
6700
  return textResponse(content2, {
6665
6701
  ...responseOpts,
6666
6702
  cacheStatus: "MISS"
@@ -6675,9 +6711,9 @@ function registerLLMsRoutes(app, options) {
6675
6711
  app.get(`/${collection}/llms-full.txt`, async () => {
6676
6712
  const cacheKey = buildLlmsFullCacheKey(collection);
6677
6713
  try {
6678
- const cached = getIfValid(llmsCache, cacheKey);
6714
+ const cached = llmsCache.get(cacheKey);
6679
6715
  if (cached) {
6680
- return textResponse(cached.content, {
6716
+ return textResponse(cached, {
6681
6717
  ...responseOptsFull,
6682
6718
  cacheStatus: "HIT"
6683
6719
  });
@@ -6699,7 +6735,7 @@ function registerLLMsRoutes(app, options) {
6699
6735
  }
6700
6736
  });
6701
6737
  console.log(`[reroute/llms] Generated ${collection}/llms-full.txt: ${stats.itemCount} items, ${formatByteSize(stats.byteSize)}MB`);
6702
- llmsCache.set(cacheKey, { content: content2, exp: Date.now() + ttlMsFull });
6738
+ llmsCache.set(cacheKey, content2, ttlMsFull);
6703
6739
  return textResponse(content2, {
6704
6740
  ...responseOptsFull,
6705
6741
  cacheStatus: "MISS"
@@ -6714,12 +6750,12 @@ function registerLLMsRoutes(app, options) {
6714
6750
  if (shouldEnableContentNegotiation(llmsConfig)) {
6715
6751
  async function handleLLMRequest(pathname, format, acceptEncoding) {
6716
6752
  const cacheKey = buildLlmsCacheKey(pathname, format, acceptEncoding);
6717
- const cached = getIfValid(llmsCache, cacheKey);
6753
+ const cached = llmsCache.get(cacheKey);
6718
6754
  if (cached) {
6719
- return format === "md" ? markdownResponse(cached.content, {
6755
+ return format === "md" ? markdownResponse(cached, {
6720
6756
  ...responseOpts,
6721
6757
  cacheStatus: "HIT"
6722
- }) : textResponse(cached.content, {
6758
+ }) : textResponse(cached, {
6723
6759
  ...responseOpts,
6724
6760
  extraHeaders: { Vary: "Accept" },
6725
6761
  cacheStatus: "HIT"
@@ -6736,7 +6772,7 @@ function registerLLMsRoutes(app, options) {
6736
6772
  format,
6737
6773
  llmsConfig
6738
6774
  });
6739
- llmsCache.set(cacheKey, { content: content2, exp: Date.now() + ttlMs });
6775
+ llmsCache.set(cacheKey, content2);
6740
6776
  return format === "md" ? markdownResponse(content2, { ...responseOpts, cacheStatus: "MISS" }) : textResponse(content2, {
6741
6777
  ...responseOpts,
6742
6778
  extraHeaders: { Vary: "Accept" },
@@ -6980,14 +7016,12 @@ function registerOGRoutes(app, options) {
6980
7016
  return pathname;
6981
7017
  }
6982
7018
  function checkOgCache(pathname, set) {
6983
- if (maxAge > 0) {
6984
- const cached = getIfValid(ogCache, pathname);
6985
- if (cached) {
6986
- set.headers["content-type"] = "image/png";
6987
- set.headers["cache-control"] = `public, max-age=${maxAge}`;
6988
- set.headers["Reroute-Cache"] = "HIT";
6989
- return new Response(cached.buffer);
6990
- }
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);
6991
7025
  }
6992
7026
  return;
6993
7027
  }
@@ -7058,9 +7092,7 @@ function registerOGRoutes(app, options) {
7058
7092
  siteName: routeOgImage?.siteName ?? ogConfig2.siteName,
7059
7093
  baseUrl: ogConfig2.baseUrl
7060
7094
  }, { width: width2, height: height2, fonts });
7061
- if (maxAge > 0) {
7062
- ogCache.set(pathname, { buffer, exp: Date.now() + maxAge * 1000 });
7063
- }
7095
+ ogCache.set(pathname, buffer);
7064
7096
  }
7065
7097
  app.get("/__reroute_og/*", async ({ request, set }) => {
7066
7098
  try {
@@ -7222,16 +7254,15 @@ function registerRobotsRoute(app, options) {
7222
7254
  sitemapEnabled,
7223
7255
  redirects
7224
7256
  } = options;
7225
- const ttlMs = toTTL(maxAge);
7226
7257
  app.get("/robots.txt", async () => {
7227
7258
  try {
7228
- const cached = getIfValid(robotsCache, "robots:main");
7259
+ const cached = robotsCache.get("robots:main");
7229
7260
  if (cached) {
7230
- return textResponse(cached.txt, { maxAge, cacheStatus: "HIT" });
7261
+ return textResponse(cached, { maxAge, cacheStatus: "HIT" });
7231
7262
  }
7232
7263
  const discovery5 = await discoverRobotsData(cwd, isWatchMode, robotsConfig, sitemapConfig, redirects);
7233
7264
  const txt = generateRobots(discovery5, robotsConfig, sitemapEnabled);
7234
- robotsCache.set("robots:main", { txt, exp: Date.now() + ttlMs });
7265
+ robotsCache.set("robots:main", txt);
7235
7266
  return textResponse(txt, { maxAge, cacheStatus: "MISS" });
7236
7267
  } catch (error) {
7237
7268
  console.error("[reroute] Failed to generate robots.txt:", error);
@@ -7244,21 +7275,24 @@ function registerRobotsRoute(app, options) {
7244
7275
  // packages/elysia/src/routes/rss.ts
7245
7276
  init_core();
7246
7277
  import { NotFoundError as NotFoundError8 } from "elysia";
7247
- 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);
7248
7286
  async function getOrDiscoverRSSData(cwd, collections2, baseUrl, isWatchMode, rssConfig) {
7249
7287
  if (isWatchMode) {
7250
7288
  return discoverRSSData(cwd, collections2, baseUrl, isWatchMode, rssConfig);
7251
7289
  }
7252
7290
  const cacheKey = "rss:discovery";
7253
7291
  const cached = rssDiscoveryCache.get(cacheKey);
7254
- if (cached && cached.exp > Date.now()) {
7255
- return cached.discovery;
7256
- }
7292
+ if (cached)
7293
+ return cached;
7257
7294
  const discovery5 = await discoverRSSData(cwd, collections2, baseUrl, isWatchMode, rssConfig);
7258
- rssDiscoveryCache.set(cacheKey, {
7259
- discovery: discovery5,
7260
- exp: Date.now() + 5 * 60 * 1000
7261
- });
7295
+ rssDiscoveryCache.set(cacheKey, discovery5);
7262
7296
  return discovery5;
7263
7297
  }
7264
7298
  function createFeedTitle(configTitle, name) {
@@ -7284,12 +7318,12 @@ async function discoverSSRRoutes(cwd, isWatchMode) {
7284
7318
  return [];
7285
7319
  }
7286
7320
  }
7287
- 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) {
7288
7322
  app.get("/feed.xml", async () => {
7289
7323
  try {
7290
- const cached = getIfValid(rssCache, "rss:main");
7324
+ const cached = rssCache.get("rss:main");
7291
7325
  if (cached) {
7292
- return feedResponse(cached.xml, format, { maxAge, cacheStatus: "HIT" });
7326
+ return feedResponse(cached, format, { maxAge, cacheStatus: "HIT" });
7293
7327
  }
7294
7328
  const discovery5 = await getOrDiscoverRSSData(cwd, collections2, baseUrl, isWatchMode, rssConfig);
7295
7329
  const allItems = [
@@ -7309,7 +7343,7 @@ async function registerMainFeedRoute(app, cwd, collections2, baseUrl, isWatchMod
7309
7343
  items: allItems
7310
7344
  };
7311
7345
  const xml = generateFeed(feed, { format, limit });
7312
- rssCache.set("rss:main", { xml, exp: Date.now() + ttlMs });
7346
+ rssCache.set("rss:main", xml);
7313
7347
  return feedResponse(xml, format, { maxAge, cacheStatus: "MISS" });
7314
7348
  } catch (error) {
7315
7349
  console.error("[reroute] Failed to generate main feed:", error);
@@ -7323,9 +7357,9 @@ function registerCollectionFeedRoutes(app, collections2, options) {
7323
7357
  app.get(`/${collection}/feed.xml`, async () => {
7324
7358
  const cacheKey = `rss:${collection}`;
7325
7359
  try {
7326
- const cached = getIfValid(options.rssCache, cacheKey);
7360
+ const cached = options.rssCache.get(cacheKey);
7327
7361
  if (cached) {
7328
- return feedResponse(cached.xml, options.format, {
7362
+ return feedResponse(cached, options.format, {
7329
7363
  maxAge: options.maxAge,
7330
7364
  cacheStatus: "HIT"
7331
7365
  });
@@ -7344,10 +7378,7 @@ function registerCollectionFeedRoutes(app, collections2, options) {
7344
7378
  format: options.format,
7345
7379
  limit: options.limit
7346
7380
  });
7347
- options.rssCache.set(cacheKey, {
7348
- xml,
7349
- exp: Date.now() + options.ttlMs
7350
- });
7381
+ options.rssCache.set(cacheKey, xml);
7351
7382
  return feedResponse(xml, options.format, {
7352
7383
  maxAge: options.maxAge,
7353
7384
  cacheStatus: "MISS"
@@ -7382,9 +7413,9 @@ async function discoverRoutesWithFeeds(ssrDataRoutes, collections2, options) {
7382
7413
  async function generateSSRDataFeed(route, options) {
7383
7414
  const routeName = route.pattern.replace(/^\//, "") || "index";
7384
7415
  const cacheKey = `rss:${routeName}`;
7385
- const cached = getIfValid(options.rssCache, cacheKey);
7416
+ const cached = options.rssCache.get(cacheKey);
7386
7417
  if (cached) {
7387
- return feedResponse(cached.xml, options.format, {
7418
+ return feedResponse(cached, options.format, {
7388
7419
  maxAge: options.maxAge,
7389
7420
  cacheStatus: "HIT"
7390
7421
  });
@@ -7406,10 +7437,7 @@ async function generateSSRDataFeed(route, options) {
7406
7437
  format: options.format,
7407
7438
  limit: options.limit
7408
7439
  });
7409
- options.rssCache.set(cacheKey, {
7410
- xml,
7411
- exp: Date.now() + options.ttlMs
7412
- });
7440
+ options.rssCache.set(cacheKey, xml);
7413
7441
  return feedResponse(xml, options.format, {
7414
7442
  maxAge: options.maxAge,
7415
7443
  cacheStatus: "MISS"
@@ -7616,21 +7644,17 @@ function registerSearchRoute(app, cwd, directive, maxAge, searchConfig) {
7616
7644
  // packages/elysia/src/routes/sitemap.ts
7617
7645
  init_core();
7618
7646
  import { NotFoundError as NotFoundError9 } from "elysia";
7619
- var sitemapDiscoveryCache = new LRUCache(1);
7647
+ var sitemapDiscoveryCache = new TTLCache(1, 5 * 60 * 1000);
7620
7648
  async function getOrDiscoverSitemapData(cwd, collections2, baseUrl, isWatchMode, sitemapConfig) {
7621
7649
  if (isWatchMode) {
7622
7650
  return discoverSitemapData(cwd, collections2, baseUrl, isWatchMode, sitemapConfig);
7623
7651
  }
7624
7652
  const cacheKey = "sitemap:discovery";
7625
7653
  const cached = sitemapDiscoveryCache.get(cacheKey);
7626
- if (cached && cached.exp > Date.now()) {
7627
- return cached.discovery;
7628
- }
7654
+ if (cached)
7655
+ return cached;
7629
7656
  const discovery5 = await discoverSitemapData(cwd, collections2, baseUrl, isWatchMode, sitemapConfig);
7630
- sitemapDiscoveryCache.set(cacheKey, {
7631
- discovery: discovery5,
7632
- exp: Date.now() + 5 * 60 * 1000
7633
- });
7657
+ sitemapDiscoveryCache.set(cacheKey, discovery5);
7634
7658
  return discovery5;
7635
7659
  }
7636
7660
  async function generateAndCacheSitemap(options, _ttlMs) {
@@ -7653,23 +7677,17 @@ function registerSitemapRoutes(app, options) {
7653
7677
  const ttlMs = toTTL(maxAge);
7654
7678
  app.get("/sitemap.xml", async () => {
7655
7679
  try {
7656
- const cached = getIfValid(sitemapCache, "sitemap:main");
7680
+ const cached = sitemapCache.get("sitemap:main");
7657
7681
  if (cached) {
7658
- return xmlResponse(cached.xml, { maxAge, cacheStatus: "HIT" });
7682
+ return xmlResponse(cached, { maxAge, cacheStatus: "HIT" });
7659
7683
  }
7660
7684
  const result = await generateAndCacheSitemap(options, ttlMs);
7661
7685
  if (result.needsIndex) {
7662
7686
  for (const page of result.pages) {
7663
- sitemapCache.set(`sitemap:${page.filename}`, {
7664
- xml: page.xml,
7665
- exp: Date.now() + ttlMs
7666
- });
7687
+ sitemapCache.set(`sitemap:${page.filename}`, page.xml);
7667
7688
  }
7668
7689
  }
7669
- sitemapCache.set("sitemap:main", {
7670
- xml: result.xml,
7671
- exp: Date.now() + ttlMs
7672
- });
7690
+ sitemapCache.set("sitemap:main", result.xml);
7673
7691
  return xmlResponse(result.xml, { maxAge, cacheStatus: "MISS" });
7674
7692
  } catch (error) {
7675
7693
  console.error("[reroute] Failed to generate sitemap:", error);
@@ -7685,19 +7703,16 @@ function registerSitemapRoutes(app, options) {
7685
7703
  const filename = `sitemap-${pageMatch[1]}.xml`;
7686
7704
  const cacheKey = `sitemap:${filename}`;
7687
7705
  try {
7688
- const cached = getIfValid(sitemapCache, cacheKey);
7706
+ const cached = sitemapCache.get(cacheKey);
7689
7707
  if (cached) {
7690
- return xmlResponse(cached.xml, { maxAge, cacheStatus: "HIT" });
7708
+ return xmlResponse(cached, { maxAge, cacheStatus: "HIT" });
7691
7709
  }
7692
7710
  const result = await generateAndCacheSitemap(options, ttlMs);
7693
7711
  const pageData = result.pages.find((p) => p.filename === filename);
7694
7712
  if (!pageData) {
7695
7713
  throw new NotFoundError9;
7696
7714
  }
7697
- sitemapCache.set(cacheKey, {
7698
- xml: pageData.xml,
7699
- exp: Date.now() + ttlMs
7700
- });
7715
+ sitemapCache.set(cacheKey, pageData.xml);
7701
7716
  return xmlResponse(pageData.xml, { maxAge, cacheStatus: "MISS" });
7702
7717
  } catch (error) {
7703
7718
  if (error instanceof NotFoundError9)
@@ -8339,13 +8354,14 @@ var reroute = () => async (app) => {
8339
8354
  const llmsEnabled = llmsConfig?.enabled === true;
8340
8355
  const robotsConfig = globalConfig.robots;
8341
8356
  const robotsEnabled = robotsConfig?.enabled === true;
8342
- const fileCache = new LRUCache(100);
8343
- const dataCache = new LRUCache(100);
8344
- const collectionCache = new LRUCache(50);
8345
- const sitemapCache = new LRUCache(20);
8346
- const rssCache = new LRUCache(20);
8347
- const ogCache = new LRUCache(100);
8348
- 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);
8349
8365
  const liveReloadState = {
8350
8366
  clients: new Set,
8351
8367
  pendingReload: false
@@ -8429,7 +8445,22 @@ var reroute = () => async (app) => {
8429
8445
  const startupCollections = await loadCollections2(cwd, isWatchMode);
8430
8446
  const startupTailwindCSS = await inlineTailwindCSS2(clientDir, false, isWatchMode);
8431
8447
  const startupIndexHtml = await loadIndexHtml2(clientDir);
8432
- 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
+ };
8433
8464
  const getTailwindCSS = isWatchMode ? () => inlineTailwindCSS2(clientDir, false, isWatchMode) : async () => startupTailwindCSS;
8434
8465
  const getIndexHtml = isWatchMode ? () => loadIndexHtml2(clientDir) : async () => startupIndexHtml;
8435
8466
  if (globalConfig.redirects && globalConfig.redirects.length > 0) {
@@ -8619,4 +8650,4 @@ export {
8619
8650
  reroute
8620
8651
  };
8621
8652
 
8622
- //# debugId=5A7719554EA87CE164756E2164756E21
8653
+ //# debugId=F52BE988669929F264756E2164756E21