|
現: 2011-11-16 (水) 15:13:47 nao-pon |
| + | #navi |
| + | RIGHT:&rsslink(../); |
| + | #boxdate |
| | | |
| + | * APC のユーザーキャッシュで XOOPS 2 のメインメニューを軽くする [#q3e274b2] |
| + | RIGHT:&tag(XOOPS,プログラミング); |
| + | |
| + | いまどき、XOOPS Cube Legacy ではない XOOPS を使っている人は少ないとは思いますが、このサイトは今日現在 XOOPS 2 で動いています。 |
| + | |
| + | で、以前から言われているメインメニューが重いというのを APC のキャッシュを使って軽くしてみようと思い立ちました。 |
| + | |
| + | APC のユーザーキャッシュを使うのは初めてなのですが、簡単に利用できるんですね。肝心の効果の程は、他の部分も重いこともあり、よくは分かりませんがなんとなく軽くなった気がします。 |
| + | |
| + | 現状ではゲストアクセスのみ有効にしていて、キャッシュ有効時間は1時間、特定の $_GET キーで、メニュー変更のあるものにもハードコーディングで対応してあります。(今回の例だと xpWiki の pgid キー) |
| + | |
| + | 気になるキャッシュサイズは、このサイトの場合で 23MB(ユーザーキャッシュ) 程使っています。 |
| + | |
| + | - modules/system/blocks/system_blocks.php |
| + | #code(php,106-){{ |
| + | function b_system_main_show() |
| + | { |
| + | global $xoopsUser,$xoopsModule; |
| + | // start nao-pon |
| + | $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.hypweb.net_mainmenu_'.$mid)) return $block; |
| + | // end nao-pon |
| + | $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 |
| + | if ((count($sublinks) > 0) && (!empty($xoopsModule)) && ($i == $mid)) { //nao-pon |
| + | 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.hypweb.net_mainmenu_'.$mid, $block, 3600); //nao-pon |
| + | return $block; |
| + | } |
| + | }} |
| + | |
| + | RIGHT:&font(90%){&page_comments;}; |
| + | #navi |