You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
On the first run this test will store the response on the filesystem:
95
+
On the first run, the test will hit real API and store the response on the filesystem:
95
96
```
96
97
.network-cache
97
98
└── example.com
@@ -100,42 +101,39 @@ On the first run this test will store the response on the filesystem:
100
101
├── headers.json
101
102
└── body.json
102
103
```
103
-
All subsequent test runs will re-use cached response and execute much faster. To invalidate that cache, delete files or provide special [options](#options).
104
+
All subsequent test runs will re-use cached response and execute much faster. You can invalidate that cache by manually deleting the files. Or provide `ttlMinutes` option to hit real API once in some period of time.
You can call `cacheRoute.GET|POST|PUT|PATCH|DELETE|ALL` to cache routes with respective HTTP method. [Url pattern](https://playwright.dev/docs/api/class-page#page-route-option-url) can contain `*` or `**` to match url segments and query params.
109
107
110
-
You can call `cacheRoute.GET|POST|PUT|PATCH|DELETE|ALL` to cache routes with respective HTTP method.
111
-
112
-
To catch requests to own APIs, you can omit hostname in [url pattern](https://playwright.dev/docs/api/class-page#page-route-option-url):
108
+
To catch requests targeting your own app APIs, you can omit hostname in url:
See more examples below or check [configuration options](#options).
121
122
122
123
## Examples
123
124
124
-
### Cache request for all tests
125
+
### Invalidate cache once in a hour
125
126
126
127
<details>
127
128
<summary>Click to expand</summary>
128
129
129
-
You can share cached response across all tests.
130
-
For that, define `cacheRoute` as an **auto** fixture and setup cached routes.
131
-
For example, to share cached response of GET `/api/cats`:
130
+
To keep response data up-to-date, you can automatically invalidate cache after configured time period. Set `ttlMinutes` option to desired value in minutes:
132
131
```ts
133
-
exportconst test =base.extend<{ cacheRoute:CacheRoute }>({
You may want to store cache files separately for a particular test. For that, you can utilize `cacheRoute.options.extraDir` - an array of extra directories to be inserted into the cache path. You can freely transform that array during the test.
304
+
By default, cache files are stored in a shared directory and re-used across tests.
305
+
You may want to isolate cache files for a particular test. For that, utilize `cacheRoute.options.extraDir` - an array of extra directories to be inserted into the cache path. You can freely transform that array during the test.
289
306
290
307
```ts
291
308
test('test', async ({ page, cacheRoute }) => {
@@ -305,7 +322,7 @@ Generated cache structure:
305
322
└── body.json
306
323
```
307
324
308
-
To store cache files in a separate directory for **all tests**,
325
+
To automatically store cache files in a separate directories for **each test**,
309
326
you can set `extraDir` option in a fixture setup:
310
327
```ts
311
328
exportconst test =base.extend<{ cacheRoute:CacheRoute }>({
@@ -337,7 +354,7 @@ the generated structure is:
337
354
<details>
338
355
<summary>Click to expand</summary>
339
356
340
-
By default, cache files are stored in `.network-cache` base directory. To change this location, use`baseDir` option:
357
+
By default, cache files are stored in `.network-cache` base directory. To change this location, set`baseDir` option:
341
358
342
359
```ts
343
360
exportconst test =base.extend<{ cacheRoute:CacheRoute }>({
0 commit comments