N
N
NOCaut2019-06-20 09:51:14
symfony
NOCaut, 2019-06-20 09:51:14

How not to cache dynamic routes in Symfony?

I am trying to add my dynamic route as a service

#routes.yml
static_pages:
    resource: 'pages.dynamic_routing_provider:getRoutes'
    type: service</blockquote>

// 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 get into this file:
> /cache/appProductionDebugSilexProjectContainerUrlMatcher.php
> /cache/appProductionDebugSilexProjectContainerUrlGenerator.php
Example:
1) I have route localhost / dynamic-pages / page1
Then in admin panel I will rename my route for page2
2) i have route localhost/dynamic-pages/page1
Then in admin panel i delete this route.
As a result, I have a problem because this route exists in the cache folder.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
P
padlyuck, 2019-06-23
@padlyuck

https://symfony.com/doc/current/routing.html#advan...

N
NOCaut, 2019-06-25
@NOCaut

padlyuck what? where is the information about how NOT to cache the route?)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question