title: Why is my Symfony 2 cache warmer called multiple times?
body: <p>One of my bundles in a Symfony 2 application has a custom cache warmer.</p>
  
  <p>When run from the console and in dev mode, it writes a notification to stdout that it has been called.</p>
  
  <p>Sometimes, not always, it is called multiple times for a single console cache:clear command as evidenced by multiple notifications being written to stdout.</p>
  
  <p>Can someone please explain why this is happening? Is it normal? Are all of the cache warmers called Multiple times?</p>
  
  <p>Environment:</p>
  
  <ul>
  <li>Ubuntu 14.04.3 </li>
  <li>PHP 7.0.2-4</li>
  <li>Symfony 2.7.9</li>
  </ul>
  
  <p>------ Edit 21-Feb-2016 08:36 -------</p>
  
  <p>It is impractical to post by actual source for various reasons (size, NDAs, etc.) So, I've created a tiny little bundle with cache warmer that just echos its class name when called.</p>
  
  <p>As you can see in the output below, it is called twice.</p>
  
  <pre><code>//
  // The cache warmer.
  //
  namespace SoBundle\Listener;
  use Symfony\Component\HttpKernel\CacheWarmer\CacheWarmerInterface;
  
  class CacheWarmer implements CacheWarmerInterface
  {
      public function isOptional()
      {
          return false;
      }
  
      public function warmUp( $cacheDir )
      {
          echo __CLASS__ . '()' . PHP_EOL;
      }
  }
  
  #
  # The service definition.
  #
  services:
      so.cache_warmer:
          class: SoBundle\Listener\CacheWarmer
          tags:
              - { name: kernel.cache_warmer }
  
  #
  # Clearing the cache...
  #
  $ console cache:clear
  Clearing the cache for the dev environment with debug true
  SoBundle\Listener\CacheWarmer()
  SoBundle\Listener\CacheWarmer()
  </code></pre>