title: How to regenerate routes cache when the configuration changes in Symfony 2
body: <p>I'm currently writing a custom route loader in Symfony 2 that will generate routes based on some configuration options defined in the main config file. The problem is that Symfony caches routes generated by custom routes loaders. Is there a way for me to update the cache when that config file changes?</p>
  
  <p>I defined a configuration like this in <code>app/config/config.yml</code></p>
  
  <pre><code>admin:
      entities:
          - BlogBundle\Entity\Post
          - BlogBundle\Entity\Comment
  </code></pre>
  
  <p>My route loader read the config file and generates some routes based on the entities. Now the problem is that once those routes are generated and cached by Symfony I can't change them unless I manually call <code>php app/console cache:clear</code>. What I mean is if I add an entity to the config:</p>
  
  <pre><code>admin:
      entities:
          - BlogBundle\Entity\Post
          - BlogBundle\Entity\Comment
          - TrainingBundle\Entity\Training
  </code></pre>
  
  <p>I will have to manually clear the cache again with <code>php app/console cache:clear</code> in order to create and cache the new routes. I want the routes cache to be invalidated if I change the config, so that a new request to the server will force the regeneration of the routes.</p>