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

Commit 1895a55

Browse files
committed
Merge pull request #408 from pine3ree/patch-7
fast-route caching doc draft
2 parents b315ea9 + 7f5a781 commit 1895a55

File tree

1 file changed

+66
-0
lines changed

1 file changed

+66
-0
lines changed

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

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,3 +271,69 @@ $container['FastRoute\RouteCollector'] = new FastRouteCollectorFactory();
271271
$container['FastRoute\RouteDispatcher'] = new FastRouteDispatcherFactory();
272272
$container['Zend\Expressive\Router\RouterInterface'] = new RouterFactory();
273273
```
274+
275+
### FastRoute caching support
276+
277+
Starting from version 1.3.0 zend-expressive-fastroute comes with support
278+
for fast-route native dispatch data caching.
279+
280+
To enable this feature a couple of changes are needed in the `routes.global.php`
281+
configuration file.
282+
283+
1. First we need to delegate the creation of the router instance to the new
284+
provided factory.
285+
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.
289+
290+
As an example:
291+
``` php
292+
// config file routes.global.php
293+
294+
return [
295+
'dependencies' => [
296+
//..
297+
'invokables' => [
298+
//..
299+
// comment or remove the following line
300+
// Zend\Expressive\Router\RouterInterface::class => Zend\Expressive\Router\FastRouteRouter::class,
301+
//..
302+
],
303+
'factories' => [
304+
//..
305+
// Add this line (the router instance is now built "in the factory")
306+
Zend\Expressive\Router\RouterInterface::class => Zend\Expressive\Router\FastRouteRouterFactory::class,
307+
//..
308+
],
309+
],
310+
311+
// the new entry for caching support
312+
'router' => [
313+
'fastroute' => [
314+
'cache_enabled' => true, // bool
315+
// optional (but recommended) cache file path
316+
'cache_file' => '/path/to/data/cache/fastroute.php.cache',
317+
],
318+
],
319+
320+
'routes' => [...],
321+
]
322+
```
323+
The new entry options are quite self-explanatory:
324+
- `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+

0 commit comments

Comments
 (0)