Skip to content

Commit

Permalink
Add two different cache intervals
Browse files Browse the repository at this point in the history
Set plugin javascript default cache interval to 3 hours due to caching issues.

Set miscellaneous cache to 3 days to avoid keeping stale content in the web browser for extend time periods.
  • Loading branch information
stickz committed Apr 7, 2023
1 parent d993a53 commit 65900c9
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
11 changes: 8 additions & 3 deletions conf/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,14 @@

$localHostedMode = false; // Set to true if rTorrent is hosted on the SAME machine as ruTorrent

$cachedPluginLoading = false; // Set to true to enable rapid cached loading of ruTorrent plugins
$cacheExpireDuration = 1*60*24; // Sets duration ruTorrent web browser cache is valid for in minutes
// Default is one day which equals 1 day x 60 minutes x 24 hours
$cachedPluginLoading = false; // Set to true to enable rapid cached loading of ruTorrent plugins
$pluginJSCacheExpire = 3*60; // Sets duration ruTorrent plugin javascript cache is valid for in minutes
// Default is 3 hours which equals 3 hours * 60 minutes due to caching issues
// Optionally raise this value and clear web browser cache when upgrading versions

$miscCacheExpire = 3*60*24; // Sets duration ruTorrent miscellaneous web browser cache is valid for in minutes
// The goal here to avoid keeping stale content in the web browser
// Default is 3 days which equals 3 days * 60 minutes * 24 hours

$localhosts = array( // list of local interfaces
"127.0.0.1",
Expand Down
5 changes: 4 additions & 1 deletion php/getplugins.php
Original file line number Diff line number Diff line change
Expand Up @@ -554,6 +554,9 @@ function testRemoteRequests($remoteRequests)

global $cachedPluginLoading;
if ($cachedPluginLoading)
CachedEcho::send($jResult,"application/javascript",true);
{
global $pluginJSCacheExpire;
CachedEcho::send($jResult,"application/javascript",true,true,$pluginJSCacheExpire);
}
else
CachedEcho::send($jResult,"application/javascript",false);
7 changes: 4 additions & 3 deletions php/utility/cachedecho.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,17 @@

class CachedEcho
{
public static function send( $content, $type = null, $cacheable = false, $exit = true )
public static function send( $content, $type = null, $cacheable = false, $exit = true, $cacheDuration = -1 )
{
header("X-Server-Timestamp: ".time());
if($cacheable && isset($_SERVER['REQUEST_METHOD']) && ($_SERVER['REQUEST_METHOD']=='GET'))
{
global $cacheExpireDuration;
global $miscCacheExpire;
$cacheAge = ($cacheDuration == -1) ? $miscCacheExpire : $cacheDuration;
$etag = '"'.strtoupper(dechex(crc32($content))).'"';
header('Expires: ');
header('Pragma: ');
header('Cache-Control: max-age='.$cacheExpireDuration);
header('Cache-Control: max-age='.$cacheAge);
if(isset($_SERVER['HTTP_IF_NONE_MATCH']) && $_SERVER['HTTP_IF_NONE_MATCH'] == $etag)
{
header('HTTP/1.0 304 Not Modified');
Expand Down

0 comments on commit 65900c9

Please sign in to comment.