From 9e19dec6bff8052870fc1f18f0e10b7410aeae78 Mon Sep 17 00:00:00 2001 From: HB9HIL Date: Sun, 1 Feb 2026 20:21:14 +0100 Subject: [PATCH] refactored the cache loader - adjusted formatting to make it easier to read - added the key prefix from config - made everything failsafe since users don't have that configured by default --- application/controllers/Api.php | 6 +++++- application/controllers/Contestcalendar.php | 6 +++++- application/controllers/Dxcalendar.php | 6 +++++- application/controllers/Sattimers.php | 6 +++++- application/libraries/Rate_limit.php | 6 +++++- application/models/Dxcluster_model.php | 6 +++++- application/models/Logbook_model.php | 6 +++++- src/Dxcc/Dxcc.php | 6 +++++- 8 files changed, 40 insertions(+), 8 deletions(-) diff --git a/application/controllers/Api.php b/application/controllers/Api.php index 811a828b7..358fc9022 100644 --- a/application/controllers/Api.php +++ b/application/controllers/Api.php @@ -1255,7 +1255,11 @@ class API extends CI_Controller { } // Load cache driver - $this->load->driver('cache', ['adapter' => $this->config->item('cache_adapter'), 'backup' => $this->config->item('cache_backup')]); + $this->load->driver('cache', [ + 'adapter' => $this->config->item('cache_adapter') ?? 'file', + 'backup' => $this->config->item('cache_backup') ?? 'file', + 'key_prefix' => $this->config->item('cache_key_prefix') ?? '' + ]); // Create cache key $cache_key = "wp_stats_{$station_id}"; diff --git a/application/controllers/Contestcalendar.php b/application/controllers/Contestcalendar.php index 4cf4005c3..6979a21af 100644 --- a/application/controllers/Contestcalendar.php +++ b/application/controllers/Contestcalendar.php @@ -126,7 +126,11 @@ class Contestcalendar extends CI_Controller { private function getRssData() { - $this->load->driver('cache', ['adapter' => $this->config->item('cache_adapter'), 'backup' => $this->config->item('cache_backup')]); + $this->load->driver('cache', [ + 'adapter' => $this->config->item('cache_adapter') ?? 'file', + 'backup' => $this->config->item('cache_backup') ?? 'file', + 'key_prefix' => $this->config->item('cache_key_prefix') ?? '' + ]); if (!$rssRawData = $this->cache->get('RssRawContestCal')) { diff --git a/application/controllers/Dxcalendar.php b/application/controllers/Dxcalendar.php index 251005180..ea024e577 100644 --- a/application/controllers/Dxcalendar.php +++ b/application/controllers/Dxcalendar.php @@ -13,7 +13,11 @@ class Dxcalendar extends CI_Controller { $data['page_title'] = __("DX Calendar"); - $this->load->driver('cache', ['adapter' => $this->config->item('cache_adapter'), 'backup' => $this->config->item('cache_backup')]); + $this->load->driver('cache', [ + 'adapter' => $this->config->item('cache_adapter') ?? 'file', + 'backup' => $this->config->item('cache_backup') ?? 'file', + 'key_prefix' => $this->config->item('cache_key_prefix') ?? '' + ]); $rssUrl = 'http://www.ng3k.com/adxo.xml'; if (!$rssRawData = $this->cache->get('RssRawDxCal')) { $rssRawData = file_get_contents($rssUrl, true); diff --git a/application/controllers/Sattimers.php b/application/controllers/Sattimers.php index 6f0166a51..4d51b45f1 100644 --- a/application/controllers/Sattimers.php +++ b/application/controllers/Sattimers.php @@ -18,7 +18,11 @@ class Sattimers extends CI_Controller { $url = 'https://www.df2et.de/tevel/api2.php?grid='.strtoupper($this->stations->find_gridsquare()); - $this->load->driver('cache', ['adapter' => $this->config->item('cache_adapter'), 'backup' => $this->config->item('cache_backup')]); + $this->load->driver('cache', [ + 'adapter' => $this->config->item('cache_adapter') ?? 'file', + 'backup' => $this->config->item('cache_backup') ?? 'file', + 'key_prefix' => $this->config->item('cache_key_prefix') ?? '' + ]); if (!$RawData = $this->cache->get('SatTimers'.strtoupper($this->stations->find_gridsquare()))) { $RawData = file_get_contents($url, true); $this->cache->save('SatTimers'.strtoupper($this->stations->find_gridsquare()), $RawData, (60*1)); diff --git a/application/libraries/Rate_limit.php b/application/libraries/Rate_limit.php index b7723b33e..85462cca8 100644 --- a/application/libraries/Rate_limit.php +++ b/application/libraries/Rate_limit.php @@ -15,7 +15,11 @@ class Rate_limit { public function __construct() { $this->CI =& get_instance(); - $this->CI->load->driver('cache', ['adapter' => $this->CI->config->item('cache_adapter'), 'backup' => $this->CI->config->item('cache_backup')]); + $this->CI->load->driver('cache', [ + 'adapter' => $this->CI->config->item('cache_adapter') ?? 'file', + 'backup' => $this->CI->config->item('cache_backup') ?? 'file', + 'key_prefix' => $this->CI->config->item('cache_key_prefix') ?? '' + ]); // Load rate limit config - if not set or empty, rate limiting is disabled $this->rate_limits = $this->CI->config->item('api_rate_limits'); diff --git a/application/models/Dxcluster_model.php b/application/models/Dxcluster_model.php index 70fddd0c4..70e6c8d63 100644 --- a/application/models/Dxcluster_model.php +++ b/application/models/Dxcluster_model.php @@ -53,7 +53,11 @@ class Dxcluster_model extends CI_Model { // Only load cache driver if caching is enabled if ($cache_band_enabled || $cache_worked_enabled) { - $this->load->driver('cache', ['adapter' => $this->config->item('cache_adapter'), 'backup' => $this->config->item('cache_backup')]); + $this->load->driver('cache', [ + 'adapter' => $this->config->item('cache_adapter') ?? 'file', + 'backup' => $this->config->item('cache_backup') ?? 'file', + 'key_prefix' => $this->config->item('cache_key_prefix') ?? '' + ]); // Garbage collection: 1% chance to clean expired cache files // Only needed when worked cache is enabled (creates many per-callsign files) diff --git a/application/models/Logbook_model.php b/application/models/Logbook_model.php index f2e2d1334..18b433965 100644 --- a/application/models/Logbook_model.php +++ b/application/models/Logbook_model.php @@ -2716,7 +2716,11 @@ class Logbook_model extends CI_Model { // Load cache driver for file caching $cache_enabled = $this->config->item('enable_dxcluster_file_cache_worked') === true; if ($cache_enabled && !isset($this->cache)) { - $this->load->driver('cache', ['adapter' => $this->config->item('cache_adapter'), 'backup' => $this->config->item('cache_backup')]); + $this->load->driver('cache', [ + 'adapter' => $this->config->item('cache_adapter') ?? 'file', + 'backup' => $this->config->item('cache_backup') ?? 'file', + 'key_prefix' => $this->config->item('cache_key_prefix') ?? '' + ]); } // Cache TTL in seconds (15 minutes = 900 seconds) diff --git a/src/Dxcc/Dxcc.php b/src/Dxcc/Dxcc.php index e3328d0a3..71227c281 100644 --- a/src/Dxcc/Dxcc.php +++ b/src/Dxcc/Dxcc.php @@ -323,7 +323,11 @@ class Dxcc { */ function read_data($date = NULL) { $CI = &get_instance(); - $CI->load->driver('cache', ['adapter' => $CI->config->item('cache_adapter'), 'backup' => $CI->config->item('cache_backup')]); + $CI->load->driver('cache', [ + 'adapter' => $CI->config->item('cache_adapter') ?? 'file', + 'backup' => $CI->config->item('cache_backup') ?? 'file', + 'key_prefix' => $CI->config->item('cache_key_prefix') ?? '' + ]); // DXCC Exceptions $cache_key = 'dxcc_exceptions_' . ($date ?? 'all');