ZF-10521: Zend_Cache_Frontend_Class output buffering issue when entity throws an exception


We came around this issue from a view helper which would obtain some data through a Zend_Cache_Frontend_Class decorator. The datasource threw an exception due to an integration issue. While the exception was handled correctly, the display turned out to be all wrong. Zend_Cache_Frontend_Class opens up output buffering to catch the output from the call and include it in the cache, but when an exception happens, it never closes the output buffering, leading to unexpected results.

First idea was to allow to disable the output buffering as we do not expect any output from those methods.

However, just cleaning up output buffering and rethrowing the exception solves the issue and has no other side-effects.

+++ Cache/Frontend/Class.php    (working copy)
@@ -218,9 +218,17 @@
             // A cache is not available (or not valid for this frontend)
-            $return = call_user_func_array(array($this->_cachedEntity, $name), $parameters);
-            $output = ob_get_contents();
-            ob_end_clean();
+            try {
+               $return = call_user_func_array(array($this->_cachedEntity, $name), $parameters);
+               $output = ob_get_contents();
+               ob_end_clean();
+            } catch (Exception $e) {
+               ob_end_clean();
+               throw $e;
+            }
             $data = array($output, $return);
             $this->save($data, $id, $this->_tags, $this->_specificLifetime, $this->_priority);


Adding the patch inline. No attachments.

fixed in r23051 (trunk)

I changed your patch to not save the result if the called method threw an exception.