|
1 | 1 | <h1 align="center">⚡ global-cache</h1> |
2 | 2 |
|
3 | | -<div align="center"> |
4 | | - |
5 | | -<p>A key-value cache for sharing data between parallel workers and test runs</p> |
6 | | - |
7 | | -[](https://github.com/vitalets/global-cache/actions/workflows/lint.yaml) |
8 | | -[](https://github.com/vitalets/global-cache/actions/workflows/test.yaml) |
9 | | - |
| 3 | +<p align="center"> |
| 4 | +A key-value cache for sharing data between parallel workers and test runs |
| 5 | +</p> |
10 | 6 |
|
11 | | -</div> |
| 7 | +<p align="center"> |
| 8 | +<a href="https://github.com/vitalets/global-cache/actions/workflows/lint.yaml"> |
| 9 | + <img alt="lint" src="https://github.com/vitalets/global-cache/actions/workflows/lint.yaml/badge.svg" /> |
| 10 | +</a> |
| 11 | +<a href="https://github.com/vitalets/global-cache/actions/workflows/test.yaml"> |
| 12 | + <img alt="test" src="https://github.com/vitalets/global-cache/actions/workflows/test.yaml/badge.svg" /> |
| 13 | +</a> |
| 14 | +<a href="https://github.com/vitalets/global-cache/blob/main/LICENSE"> |
| 15 | +<img alt="license" src="https://img.shields.io/github/license/vitalets/global-cache" /> |
| 16 | +</a> |
| 17 | +</p> |
12 | 18 |
|
13 | 19 | > \[!IMPORTANT] |
14 | 20 | > **The package was renamed** from `@vitalets/global-cache` to `@global-cache/playwright` to provide better Playwright integration. |
@@ -39,66 +45,43 @@ Under the hood, Global Cache spins up a tiny HTTP server, with a simple REST API |
39 | 45 |
|
40 | 46 | </details> |
41 | 47 |
|
42 | | -## Index |
43 | | - |
44 | | -<details><summary>Click to expand</summary> |
45 | | - |
46 | | -* [Usage (Playwright)](#usage-playwright) |
47 | | - * [Install](#install) |
48 | | - * [Configure](#configure) |
49 | | - * [Use in tests](#use-in-tests) |
50 | | - * [Dynamic keys](#dynamic-keys) |
51 | | - * [Persistent values](#persistent-values) |
52 | | -* [Examples](#examples) |
53 | | - * [Authentication (single user)](#authentication-single-user) |
54 | | - * [Authentication (multi user)](#authentication-multi-user) |
55 | | - * [Sharing a variable (BeforeAll)](#sharing-a-variable-beforeall) |
56 | | - * [Caching network request](#caching-network-request) |
57 | | - * [Cleanup (single value)](#cleanup-single-value) |
58 | | - * [Cleanup (dynamic keys)](#cleanup-dynamic-keys) |
59 | | - * [Typed cache](#typed-cache) |
60 | | -* [Configuration](#configuration) |
61 | | -* [API](#api) |
62 | | - * [`globalCache.wrap(config)`](#globalcachewrapconfig) |
63 | | - * [`globalCache.defineConfig(config)`](#globalcachedefineconfigconfig) |
64 | | - * [`globalCache.get(key,[ params,] computeFn)`](#globalcachegetkey-params-computefn) |
65 | | - * [`globalCache.getStale(key)`](#globalcachegetstalekey) |
66 | | - * [`globalCache.getStaleList(prefix)`](#globalcachegetstalelistprefix) |
67 | | - * [`globalCache.clearTestRun()`](#globalcachecleartestrun) |
68 | | - * [`globalCache.setup`](#globalcachesetup) |
69 | | - * [`globalCache.teardown`](#globalcacheteardown) |
70 | | - * [`globalCache.reporter`](#globalcachereporter) |
71 | | -* [Debug](#debug) |
72 | | -* [Changelog](#changelog) |
73 | | -* [FAQ](#faq) |
74 | | - * [How to use Global Cache in the AfterAll hook?](#how-to-use-global-cache-in-the-afterall-hook) |
75 | | -* [Feedback](#feedback) |
76 | | -* [License](#license) |
| 48 | +## `@global-cache/playwright` |
77 | 49 |
|
78 | | -</details> |
| 50 | +Currently Global Cache is primarily focused on [Playwright](https://playwright.dev/) and provides a dedicated package `@global-cache/playwright`. |
79 | 51 |
|
80 | | -## Usage (Playwright) |
| 52 | +<!-- section-toc start --> |
| 53 | + |
| 54 | +* [Installation](#installation) |
| 55 | +* [Configuration](#configuration) |
| 56 | +* [Usage](#usage) |
| 57 | +* [Dynamic keys](#dynamic-keys) |
| 58 | +* [Persistent values](#persistent-values) |
81 | 59 |
|
82 | | -Currently Global Cache is primarily developed for [Playwright](https://playwright.dev/), but can be integrated with other frameworks. |
| 60 | +<!-- section-toc end --> |
83 | 61 |
|
84 | | -### Install |
| 62 | +### Installation |
85 | 63 |
|
86 | 64 | Install via any package manager. |
87 | 65 |
|
88 | 66 | Npm: |
| 67 | + |
89 | 68 | ```sh |
90 | 69 | npm i -D @global-cache/playwright |
91 | 70 | ``` |
| 71 | + |
92 | 72 | Pnpm: |
| 73 | + |
93 | 74 | ```sh |
94 | 75 | pnpm add -D @global-cache/playwright |
95 | 76 | ``` |
| 77 | + |
96 | 78 | Yarn: |
| 79 | + |
97 | 80 | ```sh |
98 | 81 | yarn add -D @global-cache/playwright |
99 | 82 | ``` |
100 | 83 |
|
101 | | -### Configure |
| 84 | +### Configuration |
102 | 85 |
|
103 | 86 | Wrap your Playwright config with `globalCache.wrap()`: |
104 | 87 |
|
@@ -135,7 +118,19 @@ export default defineConfig({ |
135 | 118 |
|
136 | 119 | </details> |
137 | 120 |
|
138 | | -### Use in tests |
| 121 | +To provide [Global Cache options](#globalcachedefineconfigconfig), call `globalCache.config()`: |
| 122 | + |
| 123 | +```ts |
| 124 | +import { globalCache } from '@global-cache/playwright'; |
| 125 | + |
| 126 | +globalCache.config({ |
| 127 | + // ...global cache options |
| 128 | +}); |
| 129 | + |
| 130 | +// ... |
| 131 | +``` |
| 132 | + |
| 133 | +### Usage |
139 | 134 |
|
140 | 135 | In tests and hooks, wrap heavy operations with `globalCache.get(key, computeFn)` to compute the value once and share between workers: |
141 | 136 |
|
@@ -500,20 +495,6 @@ const value = await globalCache.get('foo', fn); |
500 | 495 | > \[!TIP] |
501 | 496 | > Check out a fully working example of [typed cache](/examples/typed-cache/). |
502 | 497 |
|
503 | | -## Configuration |
504 | | - |
505 | | -To provide configuration options, call `globalCache.config()`: |
506 | | - |
507 | | -```ts |
508 | | -import { globalCache } from '@global-cache/playwright'; |
509 | | - |
510 | | -globalCache.config({ |
511 | | - // ...global cache options |
512 | | -}); |
513 | | -``` |
514 | | - |
515 | | -[Available options](#globalcachedefineconfigconfig). |
516 | | - |
517 | 498 | ## API |
518 | 499 |
|
519 | 500 | `globalCache` is a singleton used to manage cache values. Import it directly from the package: |
|
0 commit comments