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
This commit is contained in:
HB9HIL
2026-02-01 20:21:14 +01:00
parent 6299e02e81
commit 9e19dec6bf
8 changed files with 40 additions and 8 deletions

View File

@@ -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}";

View File

@@ -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')) {

View File

@@ -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);

View File

@@ -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));

View File

@@ -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');

View File

@@ -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)

View File

@@ -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)

View File

@@ -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');