diff --git a/core/model/DataObject.php b/core/model/DataObject.php index 378ac949c..3f750ffc3 100755 --- a/core/model/DataObject.php +++ b/core/model/DataObject.php @@ -2646,21 +2646,29 @@ class DataObject extends ViewableData implements DataObjectInterface, i18nEntity * @return DataObject The first item matching the query */ public static function get_one($callerClass, $filter = "", $cache = true, $orderby = "") { - $sum = md5("{$filter}_{$orderby}"); - // Flush destroyed items out of the cache - if($cache && isset(DataObject::$cache_get_one[$callerClass][$sum]) && DataObject::$cache_get_one[$callerClass][$sum] instanceof DataObject && DataObject::$cache_get_one[$callerClass][$sum]->destroyed) { - DataObject::$cache_get_one[$callerClass][$sum] = false; + $SNG = singleton($callerClass); + + $cacheKey = "{$filter}-{$orderby}"; + if($extra = $SNG->extend('cacheKeyComponent')) { + $cacheKey .= '-' . implode("-", $extra); } - if(!$cache || !isset(DataObject::$cache_get_one[$callerClass][$sum])) { - $item = singleton($callerClass)->instance_get_one($filter, $orderby); + $cacheKey = md5($cacheKey); + + // Flush destroyed items out of the cache + if($cache && isset(DataObject::$cache_get_one[$callerClass][$cacheKey]) && DataObject::$cache_get_one[$callerClass][$cacheKey] instanceof DataObject && DataObject::$cache_get_one[$callerClass][$cacheKey]->destroyed) { + DataObject::$cache_get_one[$callerClass][$cacheKey + ] = false; + } + if(!$cache || !isset(DataObject::$cache_get_one[$callerClass][$cacheKey])) { + $item = $SNG->instance_get_one($filter, $orderby); if($cache) { - DataObject::$cache_get_one[$callerClass][$sum] = $item; - if(!DataObject::$cache_get_one[$callerClass][$sum]) { - DataObject::$cache_get_one[$callerClass][$sum] = false; + DataObject::$cache_get_one[$callerClass][$cacheKey] = $item; + if(!DataObject::$cache_get_one[$callerClass][$cacheKey]) { + DataObject::$cache_get_one[$callerClass][$cacheKey] = false; } } } - return $cache ? DataObject::$cache_get_one[$callerClass][$sum] : $item; + return $cache ? DataObject::$cache_get_one[$callerClass][$cacheKey] : $item; } /** diff --git a/core/model/Translatable.php b/core/model/Translatable.php index 2d7c295b7..5ea556b35 100755 --- a/core/model/Translatable.php +++ b/core/model/Translatable.php @@ -1416,6 +1416,13 @@ class Translatable extends DataObjectDecorator implements PermissionProvider { function getTranslatedLangs() { return $this->getTranslatedLocales(); } + + /** + * Return a piece of text to keep DataObject cache keys appropriately specific + */ + function cacheKeyComponent() { + return 'locale-'.self::get_current_locale()(); + } } diff --git a/core/model/Versioned.php b/core/model/Versioned.php index e61c536b9..2b0ea87fe 100755 --- a/core/model/Versioned.php +++ b/core/model/Versioned.php @@ -906,6 +906,13 @@ class Versioned extends DataObjectDecorator { function flushCache() { self::$cache_versionnumber = array(); } + + /** + * Return a piece of text to keep DataObject cache keys appropriately specific + */ + function cacheKeyComponent() { + return 'stage-'.self::current_stage(); + } } /**