Discuz!中增加memcache缓存的方法
发布时间:2020-12-14 01:39:06 所属栏目:Discuz 来源:网络整理
导读:很多站长都有体会,随着坛子越来越大,链接超时的问题越来越严峻。 google后并尝试用这里说的方法来做优化。但发现不够。被缓存的帖子不会在修改或者删除后自动清空缓存。当存在附件的帖子有权限和无权限的人看到的效果一致:要么都不能看到下载链接要么都能
很多站长都有体会,随着坛子越来越大,链接超时的问题越来越严峻。 google后并尝试用这里说的方法来做优化。但发现不够。被缓存的帖子不会在修改或者删除后自动清空缓存。当存在附件的帖子有权限和无权限的人看到的效果一致:要么都不能看到下载链接要么都能看到下载链接。 其实discuz最大的问题是帖子表cdb_threads。所以一般来说对这张表做了cache就会给论坛减轻很大的压力。 笔者做了尝试,效果还可以。所以把方法给大家看看。 先装memcache:http://blog.csdn.net/luojianlong/archive/2008/05/05/2393271.aspx.这里就不做赘述了。 1.在config.inc.php中增加 $memcachehost = '127.0.0.1'; $memcacheport = 11211; 2.在include/common.inc.php中 $mem = new Memcache; $mem->connect($memcachehost,$memcacheport); 3.在viewthread.php中 找到 $newpostanchor = $postcount = $ratelogpids = 0; $onlineauthors = array(); 在下面加上 // added by rubeljl for memcache the first page of viewthread 2009.6.8 start $postlist = Array(); $bUpdateMem = false; if( 1 == $page ){ $postlist = $mem->get( 'viewthread_' . $tid . '_1'); $bUpdateMem = empty( $postlist ) ? false : true; } $bHasAttachment = false; if( !is_array( $postlist ) || empty( $postlist ) ){ // added by rubeljl for memcache the first page of viewthread 2009.6.8 end 找到:while($post = $db->fetch_array($query)) { 在下面增加: if( $post['attachment'] ){ $bHasAttachment = true; } 找到$postlist[$post['pid']] = viewthread_procpost($post); 在下面增加: if( 1 == $page && false === $bHasAttachment ){ $mem->set( 'viewthread_' . $tid . '_1',$postlist,1000 ); } } 4.在topicadmin.php中 找到$db->query("DELETE FROM {$tablepre}posts WHERE pid IN ($pids)"); 下面添加: $mem->delete( 'viewthread_' . $tid . '_1' ); 找到:$db->query("DELETE FROM {$tablepre}myposts WHERE tid='$othertid'"); 下面添加: $mem->delete( 'viewthread_' . $tid . '_1' ); 5.在include/newreply.inc.php中 找到$pid = $db->insert_id(); 下面添加:$mem->delete( 'viewthread_' . $tid . '_1' ); (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |