mysql에서 가장 큰 부담중의 하나가 join과 group by 인데
이런 것을 안쓰고 프로그램 하기는 참 어렵습니다.
그래서, 많은 경우 file_cache를 써서 문제를 우회하고 있는데
파일 캐쉬의 파일은~ 캐쉬가 안되고, 읽을 때마다 디스크에서 올라오고
꾸준히 가해지는 이런 디스크 access는 전반적으로 시스템을 힘들게 하고
실제로 파일 캐쉬를 구현하는 것도 상당히 복잡 합니다.
db_cache를 쓰면,
구현도 간단하고,
mysql의 cache 기능을 쓰기 때문에 아주 강력한성능이 나오게 됩니다.
사용법은
b4.lib.php를 extend 디렉토리에 넣고 (불당팩의 경우 lib/b4.lib.php를 업데이트)
아래와 같이 최신글 등의 부분을 호출하면 됩니다.
db_cache(cache_key, cache_time, cache_func)
cache_key : 임의로 지정하면 되는 구분 key. 예: gr_all, gr_my_all
cache_time : 캐쉬를 하는 시간
cache_func : 캐쉬를 만드는 함수(쌍따옴표로 반드시 둘러쳐야 합니다).
-----------------------
echo db_cache('gr_trash', 300, "latest(simple, gnu4_pack)");
echo db_cache('gr_turning', 300, "latest(simple, gnu4_turning)");
echo db_cache($gr_key, 300, "latest_group('simple', $row[gr_id], 12, 40)");
echo db_cache('all_my_latest', 300, "latest_group(simple, , 12, 40, , 전체내글의반응, '$g4[bbs_path]/new.php','my_datetime')");
echo db_cache('all_latest', 300, "latest_group(simple, , 12, 40, , 전체최근글, '$g4[bbs_path]/new.php')");
echo db_cache("www-main",1,"include(./test.php)");
------------------------
물론, 아래처럼 db를 만들고 config.php에 정의도 추가해야 합니다.
$g4['cache_table'] = $g4['table_prefix'] . "cache"; // db cache 테이블
CREATE TABLE IF NOT EXISTS `g4_cache` (
`c_id` int(11) NOT NULL AUTO_INCREMENT,
`c_name` varchar(255) NOT NULL,
`c_text` text NOT NULL,
`c_datetime` datetime NOT NULL,
PRIMARY KEY (`c_id`),
UNIQUE KEY `c_name` (`c_name`)
)
db_cache Ẹ ..
DB config.php ߰߱.b4.lib.php extend ־ξµ..
ذ Ȱ.
īƮ īװ ǰ ijغմϴ.
ٰ ڵ带 ؾϴ ذ Ȱµ.
Ȥ ˷ֽ ֳ?
ȵȴٰص մϴ. (_ _)
īƮ4 īװ ϴ Լ ?
main_type1ΰ???
Լ db_cache ϸ ˴ϴ.
ǰ Ʈ ֱⰡ ʴٸ
ij صθ ӵ ־.
ο ǰ ѷִ° ִµ..
echo db_cache('test', 300, "rand()");
̷ ° ³?
̰ index.phpٰ µ ° Ѱ..
ʹ .
db_cache α ؼ db ־δ Դϴ.
<?
$list_mod = "6";
$img_width = "80";
$img_height = "80";
$td_width = (int)(100 / $list_mod);
$sql = " select *
from $g4[yc4_item_table]
where it_id <> '$it[it_id]' and it_use = '1'
order by rand()
limit 30 ";
$result = sql_query($sql);
$num = @mysql_num_rows($result);
if ($num)
include "$g4[shop_path]/maintype66.inc.php";
else
echo " ǰ õ ǰ ϴ.";
?>
̷ ֱ..
maintype66.inc.php
<?
for ($i=0; $row=sql_fetch_array($result); $i++) {
if ($i > 0 && $i % $list_mod == 0) {
echo "</tr>\n\n<tr>\n";
}
$href = "<a href='$g4[shop_path]/item.php?it_id=$row[it_id]' class=item>";
?>
<td width="<?=$td_width?>%" align=center valign=top>
<table width=98% cellpadding=1 cellspacing=0 border=0>
<tr><td height=5></td></tr>
<tr><td align=center><?=$href?><?=get_it_image($row[it_id]."_s", $img_width, $img_height)?></a></td></tr>
<tr><td align=center><?=$href?><font size='2'><?=stripslashes($row[it_name])?></font></a></td></tr>
<tr><td align=center><span class=amount><?=display_amount(get_amount($row), $row[it_tel_inq])?></span></td></tr>
</table></td>
<?
/*
// ̹ ʿ м δ (̹ ü )
if ($i%$list_mod!=$list_mod-1)
echo "<td width=1 bgcolor=#eeeeee></td>";
*/
}
// td ä.
if (($cnt = $i%$list_mod) != 0)
for ($k=$cnt; $k<$list_mod; $k++)
echo "<td> </td>\n";
?>
̷ Ǿֽϴ..
Լ ϴ Ͱ include ϴ 쿡 ȵ ֽϴ.
include "$g4[shop_path]/maintype66.inc.php";
db_cache('maintype66_key', 300, "include " . $g4[shop_path] . "/maintype66.inc.php;" )
ȵǴ ϴ.
ֱ Խù Ȯ Ź .
index ȭ鿡 츶 ֽű մϴ.
ֽű <? echo latest_group('basic_main_gr_2-Ų', '02-', '', '4-ϼ', '43-', '', '', ''); ?>
˷ֽ ؾ ھ. Ͻ ŵ.
ܿ
ijñ̸ ϴ ο ijҶ ȵǴ ɷ ˰ ֽϴ..