Adding cache mechanism for bbcode. Improving cache to use apc.

This commit is contained in:
Michael Vogel 2014-02-23 15:51:57 +01:00
parent f663676cca
commit 57db109474
2 changed files with 84 additions and 63 deletions

View file

@ -534,6 +534,9 @@ function GetProfileUsername($profile, $username) {
}
function bb_RemovePictureLinks($match) {
$text = Cache::get($match[1]);
if(is_null($text)){
$ch = @curl_init($match[1]);
@curl_setopt($ch, CURLOPT_NOBODY, true);
@curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
@ -566,11 +569,15 @@ function bb_RemovePictureLinks($match) {
$text = "[url=".$attr["content"]."]".$attr["content"]."[/url]";
}
}
Cache::set($match[1],$text);
}
return($text);
}
function bb_CleanPictureLinksSub($match) {
$text = Cache::get($match[1]);
if(is_null($text)){
$ch = @curl_init($match[1]);
@curl_setopt($ch, CURLOPT_NOBODY, true);
@curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
@ -604,7 +611,8 @@ function bb_CleanPictureLinksSub($match) {
$text = "[img]".$attr["content"]."[/img]";
}
}
Cache::set($match[1],$text);
}
return($text);
}

View file

@ -5,11 +5,20 @@
class Cache {
public static function get($key) {
if (function_exists("apc_fetch") AND function_exists("apc_exists"))
if (apc_exists($key))
return(apc_fetch($key));
$r = q("SELECT `v` FROM `cache` WHERE `k`='%s' limit 1",
dbesc($key)
);
if (count($r)) return $r[0]['v'];
if (count($r)) {
if (function_exists("apc_store"))
apc_store($key, $r[0]['v'], 600);
return $r[0]['v'];
}
return null;
}
@ -19,6 +28,10 @@
dbesc($key),
dbesc($value),
dbesc(datetime_convert()));
if (function_exists("apc_store"))
apc_store($key, $value, 600);
}