ページへ戻る

− Links

 印刷 

APC のユーザーキャッシュで XOOPS 2 のメインメニューを軽くする :: XOOPS マニア

UsersWiki:nao-pon/blog/2011-11-16


RSS of nao-pon/blog[5]
2011 11月 16 (水)
 

APC のユーザーキャッシュで XOOPS[6] 2 のメインメニューを軽くする anchor.png[7]

Tag: XOOPS[8] プログラミング[9]

いまどき、XOOPS[6] Cube Legacy ではない XOOPS[6] を使っている人は少ないとは思いますが、このサイトは今日現在 XOOPS[6] 2 で動いています。

で、以前から言われているメインメニューが重いというのを APC のキャッシュを使って軽くしてみようと思い立ちました。

APC のユーザーキャッシュを使うのは初めてなのですが、簡単に利用できるんですね。肝心の効果の程は、他の部分も重いこともあり、よくは分かりませんがなんとなく軽くなった気がします。

現状ではゲストアクセスのみ有効にしていて、キャッシュ有効時間は1時間、特定の $_GET キーで、メニュー変更のあるものにもハードコーディングで対応してあります。(今回の例だと xpWiki[10] の pgid キー)

気になるキャッシュサイズは、このサイトの場合で 23MB(ユーザーキャッシュ) 程使っています。

  • modules/system/blocks/system_blocks.php
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    
    function b_system_main_show()
    {
        global $xoopsUser,$xoopsModule;
        // start nao-pon[3]
        $mid = empty($xoopsModule)? 0 : $xoopsModule->getVar('mid');
        $checkGetKeys = array('pgid');
        foreach($checkGetKeys as $key) {
            if (array_key_exists($key, $_GET)) {
                $mid .= '_' . $key . '=' . urlencode($_GET[$key]);
            }
        }
        if (!is_object($xoopsUser) && $block = apc_fetch('xoops[6].hypweb.net_mainmenu_'.$mid)) return $block;
        // end nao-pon[3]
        $block = array();
        $block['lang_home'] = _MB_SYSTEM_HOME;
        $block['lang_close'] = _CLOSE;
        $module_handler =& xoops_gethandler('module');
        $criteria = new CriteriaCompo(new Criteria('hasmain', 1));
        $criteria->add(new Criteria('isactive', 1));
        $criteria->add(new Criteria('weight', 0, '>'));
        $modules =& $module_handler->getObjects($criteria, true);
        $moduleperm_handler =& xoops_gethandler('groupperm');
        $groups = is_object($xoopsUser) ? $xoopsUser->getGroups() : XOOPS_GROUP_ANONYMOUS;
        $read_allowed =& $moduleperm_handler->getItemIds('module_read', $groups);
        foreach (array_keys($modules) as $i) {
            if (in_array($i, $read_allowed)) {
                $block['modules'][$i]['name'] = $modules[$i]->getVar('name');
                $block['modules'][$i]['directory'] = $modules[$i]->getVar('dirname');
                $sublinks =& $modules[$i]->subLink();
    //            if ((count($sublinks) > 0) && (!empty($xoopsModule)) && ($i == $xoopsModule->getVar('mid'))) { //nao-pon[3]
                if ((count($sublinks) > 0) && (!empty($xoopsModule)) && ($i == $mid)) { //nao-pon[3]
                    foreach($sublinks as $sublink){
                        $block['modules'][$i]['sublinks'][] = array('name' => $sublink['name'], 'url' => XOOPS_URL.'/modules/'.$modules[$i]->getVar('dirname').'/'.$sublink['url']);
                    }
                } else {
                    $block['modules'][$i]['sublinks'] = array();
                }
            }
        }
        if (!is_object($xoopsUser)) apc_store('xoops[6].hypweb.net_mainmenu_'.$mid, $block, 3600); //nao-pon[3]
        return $block;
    }


Last-modified: 2011-11-16 (水) 15:13:47 (JST) (4538d) by nao-pon