title: Handling Symfony's cache in production
body: <p>I have a Symfony2 website that I'm testing in production. I went ahead and cleared its cache because I've made and will probably make more modifications, however there is a small problem:</p>
  
  <p>While the cache is being cleared and say, afterwards I want to warm it up, someone that accesses the website rebuilds the cache. That creates a small problem as the cache is being built, but not completely, while half of it gets deleted because the deletion is still in progress. </p>
  
  <p>What happens afterwards is, the cache is built, but only a part of it. Symfony thinks that the cache is built entirely, and runs without trying to build it anymore, but it runs on a half-built cache. The deletion process is a bit long (~15 sec), so in this timeframe nobody must try and create the cache by accessing the website.</p>
  
  <p>Either that, or the cache is completely built, it overwrites the old cache, and the system treats these new files as old ones, deletes part of them and some others remain. Not entirely sure, I'm not sure how to check this.</p>
  
  <p>For instance, one of the errors that I'd get is</p>
  
  <pre><code>The directory "D:\xampp\htdocs\med-app\app\app\cache\dev/jms_diextra/metadata" does not exist.
  </code></pre>
  
  <p>If I wouldn't use that bundle I'd get another cache problem from Doctrine. This appears at every website access until I delete the cache again WITHOUT anyone accessing the website. it completely blocks access to the website and makes it non-functional.</p>
  
  <p>Also, what about the warmup? That takes a while, too. What if someone accesses the website while the cache is being warmed up? Doesn't that create a conflict, too?</p>
  
  <p>How to handle this problem? Do I need to close the apache service, clear and warm cache and then restart apache? How is this handled with a website in production?</p>
  
  <p><strong>EDIT</strong>
  Something interesting that I have discovered. The bug occurs when I delete the <code>cache/prod</code> folder. If I delete the contents of the folder without deleting the folder itself, it seems the bug does not occur. I wonder why.</p>