Commit 96f32015 authored by Nigel McNie's avatar Nigel McNie
Browse files

Allow profileicon thumbnails to be cached, at least for 10 minutes.

We can't cache them for too long, because the user could change them at any time. But at least a short time is better than none, because they can be requested in batches quite a lot, for example when paging through search results.

On the profile page for the user, use 'profileiconbyid', which means that the correct image will always be shown, even when the user changes it.
parent 23dfd4d6
......@@ -167,7 +167,7 @@ function get_desired_fields(&$allfields, $desiredfields, $section) {
$return = array();
$return["{$section}description"] = array(
'type' => 'html',
'labelhtml' => ($section == 'about') ? '<div id="profileicon"><a href="' . get_config('wwwroot') . 'artefact/internal/profileicons.php"><img src="' . get_config('wwwroot') . 'thumb.php?type=profileicon&maxsize=100&id=' . $USER->get('id') . '" alt=""></a></div>' : '',
'labelhtml' => ($section == 'about') ? '<div id="profileicon"><a href="' . get_config('wwwroot') . 'artefact/internal/profileicons.php"><img src="' . get_config('wwwroot') . 'thumb.php?type=profileiconbyid&maxsize=100&id=' . intval($USER->get('profileicon')) . '" alt=""></a></div>' : '',
'value' => get_string("{$section}description", 'artefact.internal')
);
foreach ($desiredfields as $field) {
......
......@@ -48,15 +48,20 @@ switch ($type) {
if ($mimetype) {
header('Content-type: ' . $mimetype);
// We can't cache 'profileicon' because it might change,
// but 'profileiconbyid' never changes...
// We can't cache 'profileicon' for as long, because the
// user can change it at any time. But we can cache
// 'profileiconbyid' for quite a while, because it will
// never change
if ($type == 'profileiconbyid') {
// 1 week
$maxage = 604800;
header('Expires: '. gmdate('D, d M Y H:i:s', time() + $maxage) .' GMT');
header('Cache-Control: max-age=' . $maxage);
header('Pragma: public');
$maxage = 604800; // 1 week
}
else {
$maxage = 600; // 10 minutes
}
header('Expires: '. gmdate('D, d M Y H:i:s', time() + $maxage) .' GMT');
header('Cache-Control: max-age=' . $maxage);
header('Pragma: public');
readfile($path);
exit;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment