欢迎各位兄弟 发布技术文章
这里的技术是共享的
dede/content_list.php?channelid=1&cid=14
刚开始的时候 (一小时之内 )最下面的计数是 递加 1
也就是缓存 文件 让计数为0 在最初的一个时候 是递加的
content_list.php 大约100行左右
这种东西 好像是超过一个小时 之后 才从缓存中取数据
不过 如果从缓存中取的话 就有个问题 就是
最下面的计算 过了一个小时 它才有更新
unction SetCache($prefix, $key, $value, $timeout = 3600, $is_memcache = TRUE)
{
global $cache_helper_config;
$key = md5 ( $key );
/* 如果启用MC缓存 */
if (! empty ( $cache_helper_config['memcache'] ) && $cache_helper_config['memcache'] ['is_mc_enable'] === 'Y' && $is_memcache === TRUE)
{
$mc_path = empty ( $cache_helper_config['memcache'] ['mc'] [substr ( $key, 0, 1 )] ) ? $cache_helper_config['memcache'] ['mc'] ['default'] : $cache_helper_config['memcache'] ['mc'] [substr ( $key, 0, 1 )];
$mc_path = parse_url ( $mc_path );
$key = ltrim ( $mc_path ['path'], '/' ) . '_' . $prefix . '_' . $key;
if (empty ( $GLOBALS ['mc_' . $mc_path ['host']] ))
{
$GLOBALS ['mc_' . $mc_path ['host']] = new Memcache ( );
$GLOBALS ['mc_' . $mc_path ['host']]->connect ( $mc_path ['host'], $mc_path ['port'] );
//设置数据压缩门槛
//$GLOBALS ['mc_' . $mc_path ['host']]->setCompressThreshold(2048, 0.2);
}
$result = $GLOBALS ['mc_' . $mc_path ['host']]->set ( $key, $value, MEMCACHE_COMPRESSED, $timeout );
return $result;
}
$key = substr ( $key, 0, 2 ) . '/' . substr ( $key, 2, 2 ) . '/' . substr ( $key, 4, 2 ) . '/' . $key;
$tmp ['data'] = $value;
$tmp ['timeout'] = $timeout != 0 ? time () + ( int ) $timeout : 0;
$cache_data = "<?php exit('dedecms');?>\n\r".@serialize ( $tmp );
return @PutFile ( DEDEDATA . "/cache/$prefix/$key.php", $cache_data);
}才有真实的值
if ( ! function_exists('GetCache'))
{
function GetCache($prefix, $key, $is_memcache = TRUE)
{
global $cache_helper_config;
$key = md5 ( $key );
/* 如果启用MC缓存 */
if ($is_memcache === TRUE && ! empty ( $cache_helper_config['memcache'] ) && $cache_helper_config['memcache'] ['is_mc_enable'] === 'Y')
{
$mc_path = empty ( $cache_helper_config['memcache'] ['mc'] [substr ( $key, 0, 1 )] ) ? $cache_helper_config['memcache'] ['mc'] ['default'] : $cache_helper_config['memcache'] ['mc'] [substr ( $key, 0, 1 )];
$mc_path = parse_url ( $mc_path );
$key = ltrim ( $mc_path ['path'], '/' ) . '_' . $prefix . '_' . $key;
if (empty ( $GLOBALS ['mc_' . $mc_path ['host']] ))
{
$GLOBALS ['mc_' . $mc_path ['host']] = new Memcache ( );
$GLOBALS ['mc_' . $mc_path ['host']]->connect ( $mc_path ['host'], $mc_path ['port'] );
}
return $GLOBALS ['mc_' . $mc_path ['host']]->get ( $key );
}
$key = substr ( $key, 0, 2 ) . '/' . substr ( $key, 2, 2 ) . '/' . substr ( $key, 4, 2 ) . '/' . $key;
$result = @file_get_contents ( DEDEDATA . "/cache/$prefix/$key.php" );
if ($result === false)
{
return false;
}
$result = str_replace("<?php exit('dedecms');?>\n\r", "", $result);
$result = @unserialize ( $result );
if($result ['timeout'] != 0 && $result ['timeout'] < time ())
{
return false;
}
return $result ['data'];
}
}
以一个小时为限进行判断