astro-accelerator-utils 0.3.102 → 0.3.103

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.
@@ -1,5 +1,6 @@
1
1
  import { Authors } from './authors.mjs';
2
2
  import { Cache } from './cache.mjs';
3
+ import { resolveCacheMaxAge } from './cache-max-age.mjs';
3
4
  import { DateFormatter } from './dates.mjs';
4
5
  import { Markdown } from './markdown.mjs';
5
6
  import { Navigation } from './navigation.mjs';
@@ -19,7 +20,7 @@ export class Accelerator {
19
20
  * @param {Site} site
20
21
  */
21
22
  constructor(site) {
22
- this.cacheMaxAge = site.cacheMaxAge;
23
+ this.cacheMaxAge = resolveCacheMaxAge(site.cacheMaxAge);
23
24
  this.dateOptions = site.dateOptions;
24
25
  this.shortDateOptions = site.shortDateOptions;
25
26
  this.siteUrl = site.url;
@@ -0,0 +1,10 @@
1
+ export declare const DEV_CACHE_MAX_AGE = 30;
2
+ export declare const BUILD_CACHE_MAX_AGE = 300;
3
+ /**
4
+ * Resolves cache TTL from the environment and optional site config.
5
+ * Astro dev (`pnpm dev`) sets NODE_ENV to "development" → 30 seconds.
6
+ * Production builds use the configured value, or 5 minutes by default.
7
+ * @param {number | undefined} configuredMaxAge
8
+ * @returns {number}
9
+ */
10
+ export declare function resolveCacheMaxAge(configuredMaxAge: number | undefined): number;
@@ -0,0 +1,17 @@
1
+ export const DEV_CACHE_MAX_AGE = 30;
2
+ export const BUILD_CACHE_MAX_AGE = 300;
3
+
4
+ /**
5
+ * Resolves cache TTL from the environment and optional site config.
6
+ * Astro dev (`pnpm dev`) sets NODE_ENV to "development" → 30 seconds.
7
+ * Production builds use the configured value, or 5 minutes by default.
8
+ * @param {number | undefined} configuredMaxAge
9
+ * @returns {number}
10
+ */
11
+ export function resolveCacheMaxAge(configuredMaxAge) {
12
+ if (process.env.NODE_ENV === 'development') {
13
+ return DEV_CACHE_MAX_AGE;
14
+ }
15
+
16
+ return configuredMaxAge ?? BUILD_CACHE_MAX_AGE;
17
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "astro-accelerator-utils",
3
- "version": "0.3.102",
3
+ "version": "0.3.103",
4
4
  "description": "Astro utilities for Astro Accelerator.",
5
5
  "main": "index.mjs",
6
6
  "type": "module",
package/types/Site.d.ts CHANGED
@@ -25,7 +25,7 @@ export type Site = {
25
25
  pageSize: number;
26
26
  pageLinks: number;
27
27
  rssLimit: number;
28
- cacheMaxAge: number;
28
+ cacheMaxAge?: number;
29
29
  featureFlags: {
30
30
  stickyNav: {
31
31
  top: number;