<p dir="auto">HttpCache stores empty content when saving StreamedResponse because StreamedResponse:getContent returns always false</p>
<p dir="auto">This is my first Symfony bug report! I'm working with v2.3.4, and the relevant code in master branch hasn't changed since that release.</p>
<p dir="auto">Yesterday I was building a Silex controller that generates images, and I hoped to use HttpCache so I could delay generating and storing images the right way in the web root.</p>
<p dir="auto">Using Symfony's built <code class="notranslate">HttpCache\Store</code> class, I found that the method <code class="notranslate">Store::generateContentDigest()</code> and <code class="notranslate">Store::save()</code> were calling <code class="notranslate">BinaryFileResponse::getContent()</code> which returns FALSE. (So does StreamedResponse, so I assume this problem occurs in that case too.)</p>
<p dir="auto">However, the content digest returned still has a value of <code class="notranslate">en</code>, which determines the save location of the cached response. I think the checks in <code class="notranslate">Store::save()</code> all pass because this directory exists if any prior responses have been successfully cached.</p>
<p dir="auto">When the application handles other requests for the same file, it considers it a cache hit even though there is no saved content. I don't know if this is related to the code comments in <code class="notranslate">Store::lookup()</code> about returning null and purging the entry from the metadata store.</p>
<p dir="auto">Ideally, the HttpCache would cache even streaming responses, but this may only have an inelegant solution. Since actual reverse proxy caches like Varnish would be able to cache the streamed response, I don't want to avoid setting appropriate cache headers on the response in my application. I guess HttpCache should refuse to store metadata when <code class="notranslate">Response::getContent()</code> returns false.</p>