Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How clear routing cache in Symfony 2

I override routing loader (routing.loader) for set requirements key {_locale} in all my paths and set defaults this key. All locales saved in database. And i want clear routing cache (Matcher and Dumper cache class) after save new locale in database, because requirements parameter load from DB.

Thank.

like image 223
ZhukV Avatar asked Dec 27 '22 04:12

ZhukV


1 Answers

Symfony cached route files:

appDevUrlMatcher.php appDevUrlGenerator.php

in your cache dir, var/cache/dev(prod)

just delete these files

 protected function warmUpRouteCache() {

    $router = $this->get('router');
    $filesystem = $this->get('filesystem');
    $kernel = $this->get('kernel');
    $cacheDir = $kernel->getCacheDir();

    foreach (array('matcher_cache_class', 'generator_cache_class') as $option) {
        $className = $router->getOption($option);
        $cacheFile = $cacheDir . DIRECTORY_SEPARATOR . $className . '.php';
        $filesystem->remove($cacheFile);
    }

    $router->warmUp($cacheDir);
}

it works for me.

like image 84
kevin Avatar answered Jan 31 '23 00:01

kevin