How do not cache a dynamic routes

Viewed 60

I try to add my dynamic route like a service. routes.yml:

static_pages:
    resource: 'pages.dynamic_routing_provider:getRoutes'
    type: service

Service.php

class DynamicRoutingProvider {
    public function getRoutes(): RouteCollection
    {
        $builder = new RouteCollectionBuilder();

        $options = [
            'cache_dir' => null,
            'generator_cache_class' => null
        ];

        $route = new Route('dynamic-pages', ['_controller' => 'PagesBundle:Pages:preview'], [], $options);
        $builder->addRoute($route);

        return $builder->build();
    }
}

How to make my dynamic route not fall into this file:

 /cache/appProductionDebugSilexProjectContainerUrlMatcher.php
 /cache/appProductionDebugSilexProjectContainerUrlGenerator.php

Example:

  1. I have a route localhost/dynamic-pages/page1
    Then in the admin panel, I rename my route for page2
  2. I have a route localhost/dynamic-pages/page1
    Then in the admin panel, I remove this route.

In the final, I have a problem because this route exists in the cache folder.

0 Answers
Related