New cache system with subdirectories

This commit is contained in:
Michael Vogel 2012-11-17 00:50:39 +01:00
parent e67062d9cf
commit f17377e6de
7 changed files with 83 additions and 86 deletions

View file

@ -823,15 +823,13 @@ function scale_external_images($s, $include_link = true, $scale_replace = false)
$scaled = $mtch[1];
$i = fetch_url($scaled);
$cache = get_config('system','itemcache');
if (($cache != '') and is_dir($cache)) {
$cachefile = $cache."/".hash("md5", $scaled);
$cachefile = get_cachefile(hash("md5", $scaled));
if ($cachefile != '')
file_put_contents($cachefile, $i);
}
// guess mimetype from headers or filename
$type = guess_image_type($mtch[1],true);
if($i) {
$ph = new Photo($i, $type);
if($ph->is_valid()) {

View file

@ -102,18 +102,8 @@ function poller_run(&$argv, &$argc){
// clear old cache
Cache::clear();
// clear item cache files if they are older than one day
$cache = get_config('system','itemcache');
if (($cache != '') and is_dir($cache)) {
if ($dh = opendir($cache)) {
while (($file = readdir($dh)) !== false) {
$fullpath = $cache."/".$file;
if ((filetype($fullpath) == "file") and filectime($fullpath) < (time() - 86400))
unlink($fullpath);
}
closedir($dh);
}
}
// clear old item cache files
clear_cache();
$manual_id = 0;
$generation = 0;
@ -128,7 +118,7 @@ function poller_run(&$argv, &$argc){
$restart = true;
$generation = intval($argv[2]);
if(! $generation)
killme();
killme();
}
if(($argc > 1) && intval($argv[1])) {

View file

@ -962,13 +962,11 @@ if(! function_exists('prepare_body')) {
function prepare_body($item,$attach = false) {
$a = get_app();
call_hooks('prepare_body_init', $item);
call_hooks('prepare_body_init', $item);
$cache = get_config('system','itemcache');
if (($cache != '')) {
$cachefile = $cache."/".$item["guid"]."-".strtotime($item["edited"])."-".hash("crc32", $item['body']);
$cachefile = get_cachefile($item["guid"]."-".strtotime($item["edited"])."-".hash("crc32", $item['body']));
if (($cachefile != '')) {
if (file_exists($cachefile))
$s = file_get_contents($cachefile);
else {