Skip to content
This repository was archived by the owner on Jan 29, 2020. It is now read-only.

Commit d444d41

Browse files
committed
Final edits to FastRoute caching section
1 parent 1895a55 commit d444d41

File tree

1 file changed

+50
-37
lines changed

1 file changed

+50
-37
lines changed

doc/book/features/router/fast-route.md

Lines changed: 50 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -274,66 +274,79 @@ $container['Zend\Expressive\Router\RouterInterface'] = new RouterFactory();
274274

275275
### FastRoute caching support
276276

277-
Starting from version 1.3.0 zend-expressive-fastroute comes with support
278-
for fast-route native dispatch data caching.
277+
- Since zend-expressive-fastroute 1.3.0.
279278

280-
To enable this feature a couple of changes are needed in the `routes.global.php`
281-
configuration file.
279+
Starting from version 1.3.0, zend-expressive-fastroute comes with support
280+
for FastRoute native dispatch data caching.
282281

283-
1. First we need to delegate the creation of the router instance to the new
284-
provided factory.
282+
Enabling this feature requires changes to your configuration. Typically, router
283+
configuration occurs in `config/autoload/routes.global.php`; as such, we will
284+
reference that file when indicating configuration changes.
285285

286-
2. Then we need to add a new configuration entry (`$config['router']['fastroute']`).
287-
The options in this entry will be used by the factory to build the router
288-
instance in order to toggle caching support and to specify a custom cache file.
286+
The changes required are:
287+
288+
- You will need to delegate creation of the router instance to a new factory.
289+
290+
- You will need to add a new configuration entry, `$config['router']['fastroute']`.
291+
The options in this entry will be used by the factory to build the router
292+
instance in order to toggle caching support and to specify a custom cache
293+
file.
289294

290295
As an example:
296+
291297
``` php
292-
// config file routes.global.php
298+
// File config/autoload/routes.global.php
293299

294300
return [
295301
'dependencies' => [
296302
//..
297303
'invokables' => [
298-
//..
299-
// comment or remove the following line
304+
/* ... */
305+
// Comment out or remove the following line:
300306
// Zend\Expressive\Router\RouterInterface::class => Zend\Expressive\Router\FastRouteRouter::class,
301-
//..
307+
/* ... */
302308
],
303309
'factories' => [
304-
//..
305-
// Add this line (the router instance is now built "in the factory")
310+
/* ... */
311+
// Add this line; the specified factory now creates the router instance:
306312
Zend\Expressive\Router\RouterInterface::class => Zend\Expressive\Router\FastRouteRouterFactory::class,
307-
//..
313+
/* ... */
308314
],
309315
],
310316

311-
// the new entry for caching support
317+
// Add the following to enable caching support:
312318
'router' => [
313319
'fastroute' => [
314-
'cache_enabled' => true, // bool
315-
// optional (but recommended) cache file path
316-
'cache_file' => '/path/to/data/cache/fastroute.php.cache',
320+
// Enable caching support:
321+
'cache_enabled' => true,
322+
// Optional (but recommended) cache file path:
323+
'cache_file' => 'data/cache/fastroute.php.cache',
317324
],
318325
],
319326

320-
'routes' => [...],
327+
'routes' => [ /* ... */ ],
321328
]
322329
```
323-
The new entry options are quite self-explanatory:
330+
331+
The FastRoute-specific caching options are as follows:
332+
324333
- `cache_enabled` (bool) is used to toggle caching support. It's advisable to enable
325-
caching in a production environment and leave it disabled for the development
326-
environment. Commenting or omitting this option is equivalent to having it set
327-
to `false`
328-
- `cache_file` (string) This is an optional parameter that represents the path of
329-
the dispatch data cache file. It can be provided as an absolute file path or as a
330-
path relative to the zend-expressive working directory.
331-
It defaults to `data/cache/fastroute.php.cache`, where `data/cache` is the
332-
commonly defined zend-expressive cache directory created by the skeleton application.
333-
An explicit absolute file path is recommended since the php `include` construct will
334-
skip searching in the `include_path`s and the current directory.
335-
If you choose a custom path make sure that the containing directory exists
336-
and is writable by the owner of the php process. As for other zend-expressive
337-
cached configuaration, you need to purge this file in order to enable any newly
338-
added route when fast-route caching is enabled.
339-
334+
caching in a production environment and leave it disabled for the development
335+
environment. Commenting or omitting this option is equivalent to having it set
336+
to `false`. We recommend enabling it in `config/autoload/routes.global.php`,
337+
and, in development, disabling it within `config/autoload/routes.local.php` or
338+
`config/autoload/local.php`.
339+
340+
- `cache_file` (string) is an optional parameter that represents the path of
341+
the dispatch data cache file. It can be provided as an absolute file path or
342+
as a path relative to the zend-expressive working directory.
343+
344+
It defaults to `data/cache/fastroute.php.cache`, where `data/cache/` is the
345+
cache directory defined within the zend-expressive skeleton application. An
346+
explicit absolute file path is recommended since the php `include` construct
347+
will skip searching the `include_path` and the current directory.
348+
349+
If you choose a custom path, make sure that the directory exists and is
350+
writable by the owner of the PHP process. As with any other zend-expressive
351+
cached configuration, you will need to purge this file in order to enable any
352+
newly added route when FastRoute caching is enabled.

0 commit comments

Comments
 (0)