Skip to content

Commit

Permalink
Fixes #239, cacheKeyComponent updates cache key when filtering is dis…
Browse files Browse the repository at this point in the history
…abled
  • Loading branch information
Conrad committed Apr 4, 2016
1 parent e84b612 commit 07bd3c5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion code/model/Translatable.php
Expand Up @@ -1811,7 +1811,7 @@ function getTranslatedLangs() {
* 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';
}

/**
Expand Down
9 changes: 9 additions & 0 deletions tests/unit/TranslatableTest.php
Expand Up @@ -100,6 +100,15 @@ function testGetOneByLocale() {
);
$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() {
Expand Down

0 comments on commit 07bd3c5

Please sign in to comment.