create cache for config entity

This commit is contained in:
Manuel Raynaud
2013-09-16 08:56:44 +02:00
parent 7f4a69fcfb
commit 0d0d542d8b
7 changed files with 166 additions and 26 deletions

View File

@@ -16,11 +16,31 @@ use Thelia\Model\Base\ConfigQuery as BaseConfigQuery;
*
*/
class ConfigQuery extends BaseConfigQuery {
protected static $cache = array();
public static function read($search, $default = null)
{
if (array_key_exists($search, self::$cache)) {
return self::$cache[$search];
}
$value = self::create()->findOneByName($search);
return $value ? $value->getValue() : $default;
self::$cache[$search] = $value ? $value->getValue() : $default;
return self::$cache[$search];
}
public static function resetCache($key = null)
{
if($key) {
if(array_key_exists($key, self::$cache)) {
unset(self::$cache[$key]);
}
} else {
self::$cache = array();
}
}
public static function getDefaultLangWhenNoTranslationAvailable()