mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 12:05:37 +00:00
API CHANGE: Added DataObjectDecorator::cacheKeyComponent() to ensure that the cached behind DataObject::get_one() is appropriately specific (from r93095) (from r96749)
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@102378 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
parent
b8246bb433
commit
08075929ba
@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1417,6 +1417,13 @@ class Translatable extends DataObjectDecorator implements PermissionProvider {
|
||||
return $this->getTranslatedLocales();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a piece of text to keep DataObject cache keys appropriately specific
|
||||
*/
|
||||
function cacheKeyComponent() {
|
||||
return 'locale-'.self::get_current_locale()();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user