nuxt-compressed-cache 0.1.1 → 0.1.2
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/README.md +4 -1
- package/dist/module.json +1 -1
- package/dist/module.mjs +2 -1
- package/dist/runtime/tasks/prune.d.ts +7 -0
- package/dist/runtime/tasks/prune.js +12 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -119,7 +119,7 @@ export default defineNuxtConfig({
|
|
|
119
119
|
| `gzipLevel` | `6` | Gzip level, used once per render. |
|
|
120
120
|
| `statusHeader` | `'x-cache'` | Header that reports `HIT`, `STALE` or `MISS`. `false` omits it. |
|
|
121
121
|
| `invalidateOnBuild` | `true` | Tie entries to the build. After a deploy that keeps the storage, pages render again before they are sent, and payloads are kept per build (see [Payloads](#payloads)). |
|
|
122
|
-
| `cleanup` | `false` | Enable Nitro's scheduled pruning task. `true` runs daily at 04:00 and removes expired entries (see [Server helpers](#server-helpers)). An object can override `schedule` (cron) and set `olderThan` (seconds) to remove by age instead. |
|
|
122
|
+
| `cleanup` | `false` | Enable Nitro's scheduled pruning task. `true` runs daily at 04:00 and removes expired entries (see [Server helpers](#server-helpers)). An object can override `schedule` (cron) and set `olderThan` (seconds) to remove by age instead, where `0` removes every entry on each run. An invalid `olderThan` logs a warning and falls back to expiry. |
|
|
123
123
|
|
|
124
124
|
## Server helpers
|
|
125
125
|
|
|
@@ -139,6 +139,9 @@ await pruneCompressedCache()
|
|
|
139
139
|
|
|
140
140
|
// or delete entries rendered more than `olderThan` seconds ago, whatever their rule
|
|
141
141
|
await pruneCompressedCache({ olderThan: 7 * 24 * 60 * 60 })
|
|
142
|
+
|
|
143
|
+
// or delete every entry
|
|
144
|
+
await pruneCompressedCache({ olderThan: 0 })
|
|
142
145
|
```
|
|
143
146
|
|
|
144
147
|
Without `staleMaxAge`, a stale copy is served until a visit replaces it, so pruning only removes pages nobody
|
package/dist/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -28,7 +28,8 @@ const module$1 = defineNuxtModule({
|
|
|
28
28
|
...options,
|
|
29
29
|
storage: mount,
|
|
30
30
|
version: invalidateOnBuild ? nuxt.options.buildId : void 0,
|
|
31
|
-
|
|
31
|
+
// runtime config turns an `undefined` value into `''`, so an unset `olderThan` is left out
|
|
32
|
+
cleanup: cleanup ? olderThan === void 0 ? {} : { olderThan } : false
|
|
32
33
|
};
|
|
33
34
|
if (cleanup) {
|
|
34
35
|
const nitro = nuxt.options.nitro;
|
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reads `cleanup.olderThan`, which arrives as a string from an env override. `0` removes every entry on each run.
|
|
3
|
+
* Unset (`undefined` or `''`) and invalid values prune by expiry, an invalid value also warns.
|
|
4
|
+
*
|
|
5
|
+
* @returns Seconds, or `undefined` to prune by expiry.
|
|
6
|
+
*/
|
|
7
|
+
export declare function parseOlderThan(value: unknown): number | undefined;
|
|
1
8
|
/** Removes expired entries, or ones older than `cleanup.olderThan`, from the module's configured storage and prefix. */
|
|
2
9
|
declare const _default: import("nitro/types").Task<number>;
|
|
3
10
|
export default _default;
|
|
@@ -1,10 +1,21 @@
|
|
|
1
1
|
import { useRuntimeConfig } from "nitro/runtime-config";
|
|
2
2
|
import { defineTask } from "nitro/task";
|
|
3
3
|
import { pruneCompressedCache } from "../server-utils.js";
|
|
4
|
+
export function parseOlderThan(value) {
|
|
5
|
+
if (value === void 0 || value === "") {
|
|
6
|
+
return void 0;
|
|
7
|
+
}
|
|
8
|
+
const seconds = typeof value === "number" ? value : typeof value === "string" && value.trim() ? Number(value) : Number.NaN;
|
|
9
|
+
if (Number.isFinite(seconds) && seconds >= 0) {
|
|
10
|
+
return seconds;
|
|
11
|
+
}
|
|
12
|
+
console.warn(`[compressed-cache] ignoring invalid cleanup.olderThan ${JSON.stringify(value)}, pruning by expiry instead`);
|
|
13
|
+
return void 0;
|
|
14
|
+
}
|
|
4
15
|
export default defineTask({
|
|
5
16
|
meta: { name: "compressed-cache:prune", description: "Prune expired compressed cache entries" },
|
|
6
17
|
async run() {
|
|
7
18
|
const { cleanup } = useRuntimeConfig().compressedCache;
|
|
8
|
-
return { result: await pruneCompressedCache({ olderThan: cleanup.olderThan }) };
|
|
19
|
+
return { result: await pruneCompressedCache({ olderThan: parseOlderThan(cleanup.olderThan) }) };
|
|
9
20
|
}
|
|
10
21
|
});
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nuxt-compressed-cache",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.1.
|
|
4
|
+
"version": "0.1.2",
|
|
5
5
|
"description": "Serve Nuxt route rules from pre-compressed (brotli/gzip) cached copies, with stale-while-revalidate",
|
|
6
6
|
"author": "Manthankumar Satani",
|
|
7
7
|
"license": "MIT",
|