@modern-js/main-doc 0.0.0-nightly-20240703170630 → 0.0.0-nightly-20240704170700

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.
@@ -53,10 +53,10 @@ In this, customKey is used for custom cache key. By default, Modern.js will use
53
53
  ```ts
54
54
  export type CacheOptionProvider = (
55
55
  req: IncomingMessage,
56
- ) => Promise<CacheControl> | CacheControl;
56
+ ) => Promise<CacheControl | false> | CacheControl | false;
57
57
  ```
58
58
 
59
- Sometimes developers need to customise the cache key through req, which can be handled using the function form, as shown in the following code:
59
+ Sometimes developers need to customise the cache key through req or when caching does not work for specific URLs, which can be handled using the function form, as shown in the following code:
60
60
 
61
61
  ```ts title="server/cache.ts"
62
62
  import type { CacheOption, CacheOptionProvider } from '@modern-js/runtime/server';
@@ -66,6 +66,11 @@ const provider: CacheOptionProvider = (req) => {
66
66
 
67
67
  const key = computedKey(url, headers, ...);
68
68
 
69
+ if(url.includes('no-cache=1')) {
70
+ return false;
71
+ }
72
+
73
+
69
74
  return {
70
75
  maxAge: 500, // ms
71
76
  staleWhileRevalidate: 1000, // ms
@@ -55,10 +55,10 @@ export interface CacheControl {
55
55
  ```ts
56
56
  export type CacheOptionProvider = (
57
57
  req: IncomingMessage,
58
- ) => Promise<CacheControl> | CacheControl;
58
+ ) => Promise<CacheControl | false> | CacheControl | false;
59
59
  ```
60
60
 
61
- 有时开发者需要通过 req 来自定义缓存 key,可以配置为函数的形式进行处理, 例如以下代码:
61
+ 有时开发者需要通过 req 来自定义缓存 key,或者特定 url 时缓存不生效,可以配置为函数的形式进行处理, 例如以下代码:
62
62
 
63
63
  ```ts title="server/cache.ts"
64
64
 
@@ -69,6 +69,10 @@ const provider: CacheOptionProvider = (req) => {
69
69
 
70
70
  const key = computedKey(url, headers, ...);
71
71
 
72
+ if(url.includes('no-cache=1')) {
73
+ return false;
74
+ }
75
+
72
76
  return {
73
77
  maxAge: 500, // ms
74
78
  staleWhileRevalidate: 1000, // ms
package/package.json CHANGED
@@ -15,17 +15,17 @@
15
15
  "modern",
16
16
  "modern.js"
17
17
  ],
18
- "version": "0.0.0-nightly-20240703170630",
18
+ "version": "0.0.0-nightly-20240704170700",
19
19
  "publishConfig": {
20
20
  "registry": "https://registry.npmjs.org/",
21
21
  "access": "public",
22
22
  "provenance": true
23
23
  },
24
24
  "dependencies": {
25
- "@modern-js/sandpack-react": "0.0.0-nightly-20240703170630"
25
+ "@modern-js/sandpack-react": "0.0.0-nightly-20240704170700"
26
26
  },
27
27
  "peerDependencies": {
28
- "@modern-js/builder-doc": "0.0.0-nightly-20240703170630"
28
+ "@modern-js/builder-doc": "0.0.0-nightly-20240704170700"
29
29
  },
30
30
  "devDependencies": {
31
31
  "classnames": "^2",
@@ -39,8 +39,8 @@
39
39
  "@rspress/shared": "1.18.2",
40
40
  "@types/node": "^16",
41
41
  "@types/fs-extra": "9.0.13",
42
- "@modern-js/builder-doc": "0.0.0-nightly-20240703170630",
43
- "@modern-js/doc-plugin-auto-sidebar": "0.0.0-nightly-20240703170630"
42
+ "@modern-js/builder-doc": "0.0.0-nightly-20240704170700",
43
+ "@modern-js/doc-plugin-auto-sidebar": "0.0.0-nightly-20240704170700"
44
44
  },
45
45
  "scripts": {
46
46
  "dev": "rspress dev",