src/Listener/RouterCacheListener.php
public function routeSave(MvcEvent $event)
    {
        $match = $event->getRouteMatch();
        if (!$match || !$event->getRequest() instanceof HttpRequest) {
            return;
        }

        if ($event->getParam('route-cached') || !$event->getParam('route-cacheable')) {
            return;
        }

        $path = $event->getRequest()->getUri()->getPath();

        // save the route match into the cache.
        $services = $event->getApplication()->getServiceManager();

        $cacheName = $services->get(RouterCacheOptions::class)->getCache();
        $cache = $services->get($cacheName);

        $cacheKey = $this->getCacheKey($path);

        $name = $match->getMatchedRouteName();
        $data = [
            'name' => $name,
            'spec' => [
                'type' => 'Literal',
                'options' => [
                    'route' => $path,
                    'defaults' => $match->getParams(),
                ],
            ],
        ];

        $routes = $services->get('Config')['router']['routes'];
        if (isset($routes[$name])) {
            $data['spec'] = array_replace_recursive($routes[$name], $data['spec']);
        }

        $cache->setItem($cacheKey, $data);
    }
public function routeSave(MvcEvent $event)
    {
        $match = $event->getRouteMatch();
        if (!$match || !$event->getRequest() instanceof HttpRequest) {
            return;
        }

        if ($event->getParam('route-cached') || !$event->getParam('route-cacheable')) {
            return;
        }

        $path = $event->getRequest()->getUri()->getPath();

        // save the route match into the cache.
        $services = $event->getApplication()->getServiceManager();

        $cacheName = $services->get(RouterCacheOptions::class)->getCache();
        $cache = $services->get($cacheName);

        $cacheKey = $this->getCacheKey($path);

        $name = $match->getMatchedRouteName();
        $data = [
            'name' => $name,
            'spec' => [
                'type' => 'Literal',
                'options' => [
                    'route' => $path,
                    'defaults' => $match->getParams(),
                ],
            ],
        ];

        $routes = $services->get('Config')['router']['routes'];
        if (isset($routes[$name])) {
            $data['spec'] = array_replace_recursive($routes[$name], $data['spec']);
        }

        $cache->setItem($cacheKey, $data);
    }
public function routeSave ( MvcEvent $ event ) { $ match = $ event -> getRouteMatch ( ) ; if ( ! $ match || ! $ event -> getRequest ( ) instanceof HttpRequest ) { return ; } if ( $ event -> getParam ( 'route-cached' ) || ! $ event -> getParam ( 'route-cacheable' ) ) { return ; } $ path = $ event -> getRequest ( ) -> getUri ( ) -> getPath ( ) ; // save the route match into the cache. $ services = $ event -> getApplication ( ) -> getServiceManager ( ) ; $ cacheName = $ services -> get ( RouterCacheOptions :: class ) -> getCache ( ) ; $ cache = $ services -> get ( $ cacheName ) ; $ cacheKey = $ this -> getCacheKey ( $ path ) ; $ name = $ match -> getMatchedRouteName ( ) ; $ data = [ 'name' => $ name , 'spec' => [ 'type' => 'Literal' , 'options' => [ 'route' => $ path , 'defaults' => $ match -> getParams ( ) , ] , ] , ] ; $ routes = $ services -> get ( 'Config' ) [ 'router' ] [ 'routes' ] ; if ( isset ( $ routes [ $ name ] ) ) { $ data [ 'spec' ] = array_replace_recursive ( $ routes [ $ name ] , $ data [ 'spec' ] ) ; } $ cache -> setItem ( $ cacheKey , $ data ) ; }
Method that tries to save a route match into a cache

@param MvcEvent $event
Method that tries to save a route match into a cache