thyseus / yii-user-management

a user management module collection for the yii framework
185 stars 122 forks source link

Yum::t cache performance #195

Open abos5 opened 10 years ago

abos5 commented 10 years ago

In a simple page, there are more than 67 invocation like below

Serving "yum_translations_en_us_yum" from cache trace cache 10:34:22.391621
Serving "yum_translations_en_us_yum" from cache trace cache 10:34:22.392180
Serving "yum_translations_en_us_yum" from cache trace cache 10:34:22.392729
...

Obviously, it is expensive.

So, maybe there could be some other strategy like what I have done in my project.(But I have to add namespace and etc. into the source code in Yum.php . Expecting better ideas)

...
class Yum extends yum\user\models\Yum
...
public static $messages;//new 
...
public static function t
...
if(isset(self::$messages[$language]) and isset(self::$messages[$language][$category]) ) {
    $messages = self::$messages[$language][$category];//new 
} else if(Yii::app()->cache) {
    $messages = Yii::app()->cache->get($cache_id);
    self::$messages[$language][$category] = $messages;//new 
}
...

    if(Yii::app()->cache)
        Yii::app()->cache->set($cache_id, $messages);
    self::$messages[$language][$category] = $messages; //new 
...