Skip to content

Yum::t cache performance  #195

Open
Open
@abos5

Description

@abos5

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 
...

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions