Skip to content

Commit 1bf5dfe

Browse files
committed
wip
1 parent 5bfc2a7 commit 1bf5dfe

1 file changed

Lines changed: 25 additions & 1 deletion

File tree

docs/1-essentials/05-discovery.md

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ $config = new DiscoveryConfig(locations: [
259259
]);
260260
```
261261

262-
### Config and caching
262+
### Config
263263

264264
You can pass config and cache parameters into the `BootDiscovery` action, with these you can exclude files and classes from discovery, as well as config caching behavior:
265265

@@ -286,4 +286,28 @@ new BootDiscovery(
286286
)
287287
),
288288
)();
289+
```
290+
291+
### Generating and clearing Discovery cache
292+
293+
By default, discovery cache will be set to `partial`, meaning that all vendor locations will be cached. Discovery cache needs to be generated before it can be used, though. If you're using `tempest/discovery` as a standalone package, you'll have to take care of generating this cache yourself. In Tempest, this is done with a `discovery:generate` CLI command, but you're free to implement it in any other way you seem fit.
294+
295+
Actually generating the cache can be with the {b`\Tempest\Discovery\GenerateDiscoveryCache`} action:
296+
297+
```php
298+
use Tempest\Discovery\GenerateDiscoveryCache;
299+
use Tempest\Discovery\DiscoveryConfig;
300+
301+
($this->generateDiscoveryCache)(
302+
container: new Container(), // Pass in a clean container
303+
config: $discoveryConfig, // You probably already have a configured `DiscoveryConfig` from setting up discovery
304+
cache: $discoveryCache->withStrategy($strategy), // Make sure to set the strategy which you want to use for caching
305+
);
306+
```
307+
308+
It's important to note that discovery cache only works if the strategy used during generation is the same as subsequent requests. It's advised to always run cache generation code from within a script that doesn't have discovery cache enabled. For example:
309+
310+
```console
311+
~ DISCOVERY_CACHE=false bin/console discovery:generate
312+
~ DISCOVERY_CACHE=false artisan discovery:generate
289313
```

0 commit comments

Comments
 (0)