astro-accelerator-utils 0.3.101 → 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.
- package/lib/v1/accelerator.mjs +2 -1
- package/lib/v1/cache-max-age.d.mts +10 -0
- package/lib/v1/cache-max-age.mjs +17 -0
- package/lib/v1/navigation.mjs +1 -1
- package/lib/v1/posts.mjs +3 -1
- package/package.json +1 -1
- package/types/Site.d.ts +1 -1
package/lib/v1/accelerator.mjs
CHANGED
|
@@ -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/lib/v1/navigation.mjs
CHANGED
package/lib/v1/posts.mjs
CHANGED
|
@@ -24,10 +24,12 @@ export class Posts {
|
|
|
24
24
|
all () {
|
|
25
25
|
const key = 'v1_posts.all';
|
|
26
26
|
|
|
27
|
-
|
|
27
|
+
const posts = this.cache.get(key, () => {
|
|
28
28
|
const pageImportResult = this.fetchAll();
|
|
29
29
|
return Object.values(pageImportResult);
|
|
30
30
|
});
|
|
31
|
+
|
|
32
|
+
return [...posts];
|
|
31
33
|
}
|
|
32
34
|
|
|
33
35
|
/**
|
package/package.json
CHANGED