The output of drupal_render_cache_get() is not explicitly checked for FALSE, so an element who's output is an empty string is treated as a cache miss.

Attached patch fixes.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

David_Rothstein’s picture

Status: Active » Needs review
marcingy’s picture

Status: Needs review » Reviewed & tested by the community

looks good to me.

catch’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs tests, +Needs backport to D7

This is a bit yoda: FALSE !== $cached_output = drupal_render_cache_get($elements)

Could we do it another way?

Could also use a test for this one.

marcingy’s picture

Status: Needs work » Needs review
FileSize
1.76 KB

New version with less yoda and a test!

xjm’s picture

Issue tags: -Needs tests
FileSize
1.76 KB
1.12 KB
+++ b/core/modules/simpletest/tests/common.testundefined
@@ -1832,6 +1832,33 @@ class DrupalRenderTestCase extends DrupalWebTestCase {
+  /**
+   * Test caching of an empty render item.
+   */

Should be "Tests."

Attached fixes that. Test also uploaded separately to expose the failure.

Tor Arne Thune’s picture

+++ b/core/modules/simpletest/tests/common.test
@@ -1832,6 +1832,33 @@ class DrupalRenderTestCase extends DrupalWebTestCase {
+    // Make sure we did go via the render process.

This made me stop and wonder. Would it be better to say: "Make sure the render process got the cache for the empty render item." ...or have I misunderstood?

Rest looks good :)

xjm’s picture

Assigned: Unassigned » xjm
Status: Needs review » Needs work

Thanks @Tor Arne Thune! I'll polish the inline docs a little. Edit: But, um, not at 3a. That could end badly. :)

xjm’s picture

Status: Needs work » Needs review
FileSize
1.33 KB
1.89 KB

Clarified the inline comments a bit.

aspilicious’s picture

Looks good and sane.

xjm’s picture

chx in IRC:

$this->assertTrue(!isset($element['#printed']), t('Cache hit')); this should be assertFalse

Fixed here.

chx’s picture

Status: Needs review » Reviewed & tested by the community

I am very happy to see render cache enhancements given how much me (and my client, thanks ITV for sponsoring my time on this review) rely on it.

David_Rothstein’s picture

+    // Force a request via GET.
+    $_SERVER['REQUEST_METHOD'] = 'GET';

Should this be set back to its previous value at the end of the test? (Offhand, I'm not sure how much it matters.)

catch’s picture

Status: Reviewed & tested by the community » Needs work

I'm not sure how much it matters either, but I also don't want to find out in three months that it does, so could we do a quick re-roll for that?

xjm’s picture

Status: Needs work » Needs review
FileSize
861 bytes
2.04 KB

So, uh. Like this?

catch’s picture

Status: Needs review » Reviewed & tested by the community

Yep.

catch’s picture

Status: Reviewed & tested by the community » Patch (to be ported)

Committed/pushed to 8.x, thanks folks.

Moving back to 7.x for backport.

oriol_e9g’s picture

Version: 8.x-dev » 7.x-dev
Status: Patch (to be ported) » Needs review
FileSize
1.99 KB
1.42 KB

Fast port for D7.11 including consideration.

marcingy’s picture

Status: Needs review » Reviewed & tested by the community

Straight forward port if the bot comes back green this looks good.

webchick’s picture

Status: Reviewed & tested by the community » Fixed

Looks like a straight-up bug fix to me. Thanks for the tests!

Committed and pushed to 7.x.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

xjm’s picture

Assigned: xjm » Unassigned