Commit b45e4637 authored by Hugh Davenport's avatar Hugh Davenport Committed by Son Nguyen
Browse files

Add nocache config option



When nocache is true, don't send caching directives with HTTP
response.

Change-Id: Ib9b958ecb035834eeabda150e6dc9bee9cfcc3ce
Signed-off-by: default avatarHugh Davenport <hugh@catalyst.net.nz>
parent 153bcb66
......@@ -33,11 +33,13 @@ $type = param_alphanumext('type');
if (preg_match('/^([a-z]*_)?(viewtypes|weekly)$/', $type) ||
$type == 'institutions' || $type == 'grouptypes') {
$maxage = 3600;
header('Content-type: ' . 'image/png');
header('Expires: '. gmdate('D, d M Y H:i:s', time() + $maxage) .' GMT');
header('Cache-Control: max-age=' . $maxage);
header('Pragma: public');
if (!get_config('nocache')) {
$maxage = 3600;
header('Expires: '. gmdate('D, d M Y H:i:s', time() + $maxage) .' GMT');
header('Cache-Control: max-age=' . $maxage);
header('Pragma: public');
}
readfile(get_config('dataroot') . 'images/' . $type . '.png');
exit;
......
......@@ -330,3 +330,6 @@ $cfg->cleanurlusereditable = true;
// The following option if enabled will allow users to choose also standard site themes as their preferred theme
// for browsing the site.
// $cfg->sitethemeprefs = true;
// Turn on caching of HTTP requests
// $cfg->nocache = true;
......@@ -101,7 +101,7 @@ function serve_file($path, $filename, $mimetype, $options=array()) {
header('Content-Disposition: inline; filename="' . $filename . '"');
}
if ($options['lifetime'] > 0) {
if ($options['lifetime'] > 0 && !get_config('nocache')) {
header('Cache-Control: max-age=' . $options['lifetime']);
header('Expires: '. gmdate('D, d M Y H:i:s', time() + $options['lifetime']) .' GMT');
header('Pragma: ');
......
......@@ -30,10 +30,12 @@ define('NOCHECKREQUIREDFIELDS', 1);
require('init.php');
header('Content-type: text/css');
$maxage = 604800;
header('Expires: '. gmdate('D, d M Y H:i:s', time() + $maxage) .' GMT');
header('Cache-Control: max-age=' . $maxage);
header('Pragma: public');
if (!get_config('nocache')) {
$maxage = 604800;
header('Expires: '. gmdate('D, d M Y H:i:s', time() + $maxage) .' GMT');
header('Cache-Control: max-age=' . $maxage);
header('Pragma: public');
}
if ($style = param_integer('id', null)) {
echo get_field('style', 'css', 'id', $style);
......
......@@ -76,19 +76,21 @@ switch ($type) {
if ($mimetype) {
header('Content-type: ' . $mimetype);
// 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' and !$earlyexpiry) {
$maxage = 604800; // 1 week
}
else {
$maxage = 600; // 10 minutes
if (!get_config('nocache')) {
// 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' and !$earlyexpiry) {
$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');
}
header('Expires: '. gmdate('D, d M Y H:i:s', time() + $maxage) .' GMT');
header('Cache-Control: max-age=' . $maxage);
header('Pragma: public');
readfile_exit($path);
}
......@@ -103,14 +105,16 @@ switch ($type) {
// We couldn't find an image for this user. Attempt to use the 'no user
// photo' image for the current theme
// We can cache such images
$maxage = 604800; // 1 week
if ($earlyexpiry) {
$maxage = 600; // 10 minutes
if (!get_config('nocache')) {
// We can cache such images
$maxage = 604800; // 1 week
if ($earlyexpiry) {
$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');
}
header('Expires: '. gmdate('D, d M Y H:i:s', time() + $maxage) .' GMT');
header('Cache-Control: max-age=' . $maxage);
header('Pragma: public');
if ($path = get_dataroot_image_path('artefact/file/profileicons/no_userphoto/' . $THEME->basename, 0, $size)) {
header('Content-type: ' . 'image/png');
......@@ -142,10 +146,12 @@ switch ($type) {
if ($path = get_dataroot_image_path('artefact/file/profileicons', $filedata->fileid, get_imagesize_parameters())) {
if ($filedata->filetype) {
header('Content-type: ' . $filedata->filetype);
$maxage = 604800;
header('Expires: '. gmdate('D, d M Y H:i:s', time() + $maxage) .' GMT');
header('Cache-Control: max-age=' . $maxage);
header('Pragma: public');
if (!get_config('nocache')) {
$maxage = 604800;
header('Expires: '. gmdate('D, d M Y H:i:s', time() + $maxage) .' GMT');
header('Cache-Control: max-age=' . $maxage);
header('Pragma: public');
}
readfile_exit($path);
}
......@@ -164,10 +170,12 @@ switch ($type) {
$basepath = 'artefact/' . $ap . '/' . $basepath;
}
header('Content-type: image/png');
$maxage = 604800;
header('Expires: '. gmdate('D, d M Y H:i:s', time() + $maxage) .' GMT');
header('Cache-Control: max-age=' . $maxage);
header('Pragma: public');
if (!get_config('nocache')) {
$maxage = 604800;
header('Expires: '. gmdate('D, d M Y H:i:s', time() + $maxage) .' GMT');
header('Cache-Control: max-age=' . $maxage);
header('Pragma: public');
}
$path = $THEME->get_path('images/thumb.png', false, $basepath);
if (is_readable($path)) {
readfile_exit($path);
......
Supports Markdown
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