diff --git a/code/model/Translatable.php b/code/model/Translatable.php index 3699ed8..98e10ea 100755 --- a/code/model/Translatable.php +++ b/code/model/Translatable.php @@ -1811,7 +1811,7 @@ class Translatable extends DataExtension implements PermissionProvider { * Return a piece of text to keep DataObject cache keys appropriately specific */ function cacheKeyComponent() { - return 'locale-'.self::get_current_locale(); + return self::locale_filter_enabled() ? 'locale-'.self::get_current_locale() : 'locale-filter-disabled'; } /** diff --git a/tests/unit/TranslatableTest.php b/tests/unit/TranslatableTest.php index 1f653c1..5f990de 100755 --- a/tests/unit/TranslatableTest.php +++ b/tests/unit/TranslatableTest.php @@ -100,6 +100,15 @@ class TranslatableTest extends FunctionalTest { ); $this->assertEquals($translated->ID, $found->ID); Translatable::enable_locale_filter(); + + //test caching of get_one when filtering is disabled + Translatable::set_current_locale('de_DE'); //cache failed lookup + $notFound = DataObject::get_one('SiteTree', '"URLSegment" = \'home\''); + $this->assertFalse($notFound, 'Should not have found a home page for de_DE'); + Translatable::disable_locale_filter(); + $found = DataObject::get_one('SiteTree', '"URLSegment" = \'home\''); + $this->assertInstanceOf('DataObject', $found, 'Should have found a home page with locale filtering off'); + Translatable::enable_locale_filter(); } function testLocaleFilteringEnabledAndDisabled() {