From 4f13ebf9c7b8c4b42cb595ba82fd146911476be0 Mon Sep 17 00:00:00 2001 From: Szymon Porwolik Date: Sat, 1 Nov 2025 19:23:45 +0100 Subject: [PATCH] Config.php setting for file cache --- application/config/config.sample.php | 18 +++++++++++++++ application/models/Dxcluster_model.php | 32 ++++++++++++++++++-------- 2 files changed, 41 insertions(+), 9 deletions(-) diff --git a/application/config/config.sample.php b/application/config/config.sample.php index d521c6908..f6f393181 100644 --- a/application/config/config.sample.php +++ b/application/config/config.sample.php @@ -797,3 +797,21 @@ $config['max_login_attempts'] = 3; */ $config['enable_dcl_interface'] = true; + + /* + |-------------------------------------------------------------------------- + | DXCluster File Cache + |-------------------------------------------------------------------------- + | + | Controls whether DXCluster data is cached to files on the server. + | + | Set to TRUE to enable file caching (may cause high disk usage on large installations) + | Set to FALSE to disable file caching (recommended for most installations) + | + | Default: false (file caching disabled) + | + | Warning: This is experimental and may not work as expected in all environments. + |-------------------------------------------------------------------------- + */ + + $config['enable_dxcluster_file_cache'] = false; diff --git a/application/models/Dxcluster_model.php b/application/models/Dxcluster_model.php index 8eef20d0b..2a891b675 100644 --- a/application/models/Dxcluster_model.php +++ b/application/models/Dxcluster_model.php @@ -34,16 +34,21 @@ class Dxcluster_model extends CI_Model { public function dxc_spotlist($band = '20m', $maxage = 60, $de = '', $mode = 'All') { $this->load->helper(array('psr4_autoloader')); - // Load cache driver once - $this->load->driver('cache', array('adapter' => 'file', 'backup' => 'file')); + // Check if file caching is enabled in config + $cache_enabled = $this->config->item('enable_dxcluster_file_cache') === true; - // Check cache first for processed spot list + // Only load cache driver if caching is enabled + if ($cache_enabled) { + $this->load->driver('cache', array('adapter' => 'file', 'backup' => 'file')); + } + + // Check cache first for processed spot list (only if caching is enabled) $user_id = $this->session->userdata('user_id'); $logbook_id = $this->session->userdata('active_station_logbook'); $cache_key = "spotlist_{$band}_{$maxage}_{$de}_{$mode}_{$user_id}_{$logbook_id}"; - // Try to get cached processed results (59 second cache) - if ($cached_spots = $this->cache->get($cache_key)) { + // Try to get cached processed results (59 second cache) only if caching is enabled + if ($cache_enabled && ($cached_spots = $this->cache->get($cache_key))) { return $cached_spots; } @@ -64,7 +69,13 @@ class Dxcluster_model extends CI_Model { $this->load->model('logbook_model'); $logbooks_locations_array = $this->logbooks_model->list_logbook_relationships($this->session->userdata('active_station_logbook')); - if (!$jsonraw = $this->cache->get('dxcache'.$band)) { + // Check cache for raw DX cluster data (only if caching is enabled) + $jsonraw = null; + if ($cache_enabled) { + $jsonraw = $this->cache->get('dxcache'.$band); + } + + if (!$jsonraw) { // CURL Functions $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $dxcache_url); @@ -82,7 +93,10 @@ class Dxcluster_model extends CI_Model { return []; } - $this->cache->save('dxcache'.$band, $jsonraw, 59); // Cache DXClusterCache Instancewide for 59seconds + // Save to cache only if caching is enabled + if ($cache_enabled) { + $this->cache->save('dxcache'.$band, $jsonraw, 59); // Cache DXClusterCache Instancewide for 59seconds + } } // Validate JSON before decoding @@ -250,8 +264,8 @@ class Dxcluster_model extends CI_Model { } } - // Cache the processed results for 59 seconds (matches DXCache server TTL) - if (!empty($spotsout)) { + // Cache the processed results for 59 seconds (matches DXCache server TTL) only if caching is enabled + if ($cache_enabled && !empty($spotsout)) { $this->cache->save($cache_key, $spotsout, 59); }