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

Issue Type: Patch Created: 2010-10-06T11:36:55.000+0000 Last Updated: 2010-10-07T10:05:12.000+0000 Status: Resolved Fix version(s): - 1.11.1 (30/Nov/10)

Reporter: Louis-Philippe Huberdeau (lphuberdeau) Assignee: Marc Bennewitz (private) (mabe) Tags: - Zend_Cache

Related issues: Attachments:


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.

<pre class="highlight">
+++ 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);


Posted by Louis-Philippe Huberdeau (lphuberdeau) on 2010-10-06T11:45:29.000+0000

Adding the patch inline. No attachments.

Posted by Marc Bennewitz (private) (mabe) on 2010-10-07T10:05:11.000+0000

fixed in r23051 (trunk)

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

Have you found an issue?

See the Overview section for more details.


© 2006-2018 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.