Skip to content

Commit

Permalink
Debug v12 - fix delay of cache
Browse files Browse the repository at this point in the history
  • Loading branch information
eldy committed Mar 2, 2025
1 parent c2aa1fe commit 812d9ad
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 9 deletions.
2 changes: 1 addition & 1 deletion htdocs/core/lib/website.lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,7 @@ function redirectToContainer($containerref, $containeraliasalt = '', $containeri
unset($tmpwebsitepage);
}
if ($result > 0) {
$currenturi = $_SERVER["REQUEST_URI"]; // Example: /public/website/index.php?website=mywebsite.com&pageref=mywebsite-home&nocache=1708177483
$currenturi = $_SERVER["REQUEST_URI"]; // Example: /public/website/index.php?website=mywebsite.com&pageref=mywebsite-home&cache=3600
$regtmp = array();
if (preg_match('/&pageref=([^&]+)/', $currenturi, $regtmp)) {
if ($regtmp[0] == $containerref) {
Expand Down
11 changes: 4 additions & 7 deletions htdocs/viewimage.php
Original file line number Diff line number Diff line change
Expand Up @@ -189,20 +189,17 @@ function llxFooter($comment = '', $zone = 'private', $disabledoutputofmessages =
* View
*/

if (GETPOST("cache", 'alpha')) {
$cachestring = GETPOST("cache", 'aZ09'); // May be 1, or an int, or a hash
if ($cachestring) {
// Important: The following code is to avoid a page request by the browser and PHP CPU at each Dolibarr page access.
// We are here when param cache=xxx to force a cache policy:
// xxx=1 means cache of 3600s
// xxx=abcdef or 123456789 means a cache of 1 week (the key will be modified to get break cache use)
if (empty($dolibarr_nocache)) {
if (GETPOST('cache', 'alpha') != '1') {
$delaycache = 3600 * 24 * 7;
} else {
$delaycache = 3600;
}
$delaycache = ((is_numeric($cachestring) && (int) $cachestring > 1 && (int) $cachestring < 999999) ? $cachestring : '3600');
header('Cache-Control: max-age='.$delaycache.', public, must-revalidate');
header('Pragma: cache'); // This is to avoid to have Pragma: no-cache set by proxy or web server
header('Expires: '.gmdate('D, d M Y H:i:s', time() + $delaycache).' GMT'); // This is to avoid to have Expires set by proxy or web server
header('Expires: '.gmdate('D, d M Y H:i:s', time() + (int) $delaycache).' GMT'); // This is to avoid to have Expires set by proxy or web server
} else {
// If any cache on files were disable by config file (for test purpose)
header('Cache-Control: no-cache');
Expand Down
4 changes: 3 additions & 1 deletion htdocs/website/samples/wrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,10 @@
if ($cachestring || image_format_supported($original_file) >= 0) {
// Important: Following code is to avoid page request by browser and PHP CPU at
// each Dolibarr page access.
header('Cache-Control: max-age='.((is_numeric($cachestring) && (int) $cachestring > 1 && (int) $cachestring < 999999) ? $cachestring : '3600').', public, must-revalidate');
$delaycache = ((is_numeric($cachestring) && (int) $cachestring > 1 && (int) $cachestring < 999999) ? $cachestring : '3600');
header('Cache-Control: max-age='.$cachedelay.', public, must-revalidate');
header('Pragma: cache'); // This is to avoid having Pragma: no-cache
header('Expires: '.gmdate('D, d M Y H:i:s', time() + (int) $delaycache).' GMT'); // This is to avoid to have Expires set by proxy or web server
}

$refname = basename(dirname($original_file)."/");
Expand Down

0 comments on commit 812d9ad

Please sign in to comment.