mirror of
https://git.friendi.ca/friendica/friendica-addons.git
synced 2024-11-22 04:43:40 +00:00
privacy_image_cache: A file cache is implemented that should be much faster than the database.
This commit is contained in:
parent
97209cee75
commit
4437c42fd4
1 changed files with 22 additions and 0 deletions
|
@ -43,6 +43,24 @@ function privacy_image_cache_init() {
|
||||||
// Double encoded url - happens with Diaspora
|
// Double encoded url - happens with Diaspora
|
||||||
$urlhash2 = 'pic:' . sha1(urldecode($_REQUEST['url']));
|
$urlhash2 = 'pic:' . sha1(urldecode($_REQUEST['url']));
|
||||||
|
|
||||||
|
$cache = get_config('system','itemcache');
|
||||||
|
if (($cache != '') and is_dir($cache)) {
|
||||||
|
$cachefile = $cache."/".hash("md5", $urlhash);
|
||||||
|
if (file_exists($cachefile)) {
|
||||||
|
$img_str = file_get_contents($cachefile);
|
||||||
|
|
||||||
|
$mime = image_type_to_mime_type(exif_imagetype($cachefile));
|
||||||
|
|
||||||
|
header("Content-type: $mime");
|
||||||
|
header("Expires: " . gmdate("D, d M Y H:i:s", time() + (3600*24)) . " GMT");
|
||||||
|
header("Cache-Control: max-age=" . (3600*24));
|
||||||
|
|
||||||
|
echo $img_str;
|
||||||
|
|
||||||
|
killme();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$r = q("SELECT * FROM `photo` WHERE `resource-id` in ('%s', '%s') LIMIT 1", $urlhash, $urlhash2);
|
$r = q("SELECT * FROM `photo` WHERE `resource-id` in ('%s', '%s') LIMIT 1", $urlhash, $urlhash2);
|
||||||
if (count($r)) {
|
if (count($r)) {
|
||||||
$img_str = $r[0]['data'];
|
$img_str = $r[0]['data'];
|
||||||
|
@ -98,6 +116,10 @@ function privacy_image_cache_init() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Writing in cachefile
|
||||||
|
if (isset($cachefile) && $cachefile != '')
|
||||||
|
file_put_contents($cachefile, $img_str);
|
||||||
|
|
||||||
header("Content-type: $mime");
|
header("Content-type: $mime");
|
||||||
header("Expires: " . gmdate("D, d M Y H:i:s", time() + (3600*24)) . " GMT");
|
header("Expires: " . gmdate("D, d M Y H:i:s", time() + (3600*24)) . " GMT");
|
||||||
header("Cache-Control: max-age=" . (3600*24));
|
header("Cache-Control: max-age=" . (3600*24));
|
||||||
|
|
Loading…
Reference in a new issue