From 3a2bce86469eaf229910b2bf4dc4c7234ffb2a99 Mon Sep 17 00:00:00 2001 From: HB9HIL Date: Sun, 1 Feb 2026 19:33:51 +0100 Subject: [PATCH] make the cache adapter as config options and use them when calling the cache lib --- application/config/config.sample.php | 28 ++++++++++++++++++--- application/controllers/Api.php | 2 +- application/controllers/Contestcalendar.php | 2 +- application/controllers/Dxcalendar.php | 2 +- application/controllers/Sattimers.php | 2 +- application/libraries/Rate_limit.php | 2 +- application/models/Dxcluster_model.php | 2 +- application/models/Logbook_model.php | 2 +- src/Dxcc/Dxcc.php | 2 +- 9 files changed, 33 insertions(+), 11 deletions(-) diff --git a/application/config/config.sample.php b/application/config/config.sample.php index c0c59d876..fc29e2eca 100644 --- a/application/config/config.sample.php +++ b/application/config/config.sample.php @@ -384,14 +384,36 @@ $config['error_views_path'] = ''; /* |-------------------------------------------------------------------------- -| Cache Directory Path +| Cache Configuration |-------------------------------------------------------------------------- | -| Leave this BLANK unless you would like to set something other than the default -| application/cache/ directory. Use a full server path with trailing slash. +| CodeIgniter supports multiple cache adapters to improve application performance +| by storing frequently accessed data. +| +| 'cache_path' +| Directory path for file-based caching. Leave BLANK to use the default +| application/cache/ directory. Use absolute paths with trailing slash. +| Must be writable by the web server (typically www-data or apache user). +| Example: /var/cache/wavelog/ or /tmp/wavelog_cache/ +| +| 'cache_adapter' +| The primary cache adapter to use. Options include: +| - 'file' : File-based caching (default, works everywhere) +| - 'redis' : Redis in-memory cache (requires Redis server & extension) +| - 'memcached' : Memcached (requires Memcached server & extension) +| - 'apc' : APC/APCu in-memory cache (requires APCu extension) +| - 'wincache' : Windows Cache (requires WinCache extension) +| +| 'cache_backup' +| Fallback adapter if primary adapter fails or is unavailable. +| Recommended: 'file' as a safe fallback option +| +| Note: Redis configuration is stored separately in application/config/redis.php | */ $config['cache_path'] = ''; +$config['cache_adapter'] = 'file'; +$config['cache_backup'] = 'file'; /* |-------------------------------------------------------------------------- diff --git a/application/controllers/Api.php b/application/controllers/Api.php index 4336198ee..811a828b7 100644 --- a/application/controllers/Api.php +++ b/application/controllers/Api.php @@ -1255,7 +1255,7 @@ class API extends CI_Controller { } // Load cache driver - $this->load->driver('cache', ['adapter' => 'file']); + $this->load->driver('cache', ['adapter' => $this->config->item('cache_adapter'), 'backup' => $this->config->item('cache_backup')]); // Create cache key $cache_key = "wp_stats_{$station_id}"; diff --git a/application/controllers/Contestcalendar.php b/application/controllers/Contestcalendar.php index 8ba2aff11..4cf4005c3 100644 --- a/application/controllers/Contestcalendar.php +++ b/application/controllers/Contestcalendar.php @@ -126,7 +126,7 @@ class Contestcalendar extends CI_Controller { private function getRssData() { - $this->load->driver('cache', array('adapter' => 'file', 'backup' => 'file')); + $this->load->driver('cache', ['adapter' => $this->config->item('cache_adapter'), 'backup' => $this->config->item('cache_backup')]); if (!$rssRawData = $this->cache->get('RssRawContestCal')) { diff --git a/application/controllers/Dxcalendar.php b/application/controllers/Dxcalendar.php index 991448576..251005180 100644 --- a/application/controllers/Dxcalendar.php +++ b/application/controllers/Dxcalendar.php @@ -13,7 +13,7 @@ class Dxcalendar extends CI_Controller { $data['page_title'] = __("DX Calendar"); - $this->load->driver('cache', array('adapter' => 'file', 'backup' => 'file')); + $this->load->driver('cache', ['adapter' => $this->config->item('cache_adapter'), 'backup' => $this->config->item('cache_backup')]); $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 053c26e3b..6f0166a51 100644 --- a/application/controllers/Sattimers.php +++ b/application/controllers/Sattimers.php @@ -18,7 +18,7 @@ class Sattimers extends CI_Controller { $url = 'https://www.df2et.de/tevel/api2.php?grid='.strtoupper($this->stations->find_gridsquare()); - $this->load->driver('cache', array('adapter' => 'file', 'backup' => 'file')); + $this->load->driver('cache', ['adapter' => $this->config->item('cache_adapter'), 'backup' => $this->config->item('cache_backup')]); 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 8fcb64068..b7723b33e 100644 --- a/application/libraries/Rate_limit.php +++ b/application/libraries/Rate_limit.php @@ -15,7 +15,7 @@ class Rate_limit { public function __construct() { $this->CI =& get_instance(); - $this->CI->load->driver('cache', ['adapter' => 'file']); + $this->CI->load->driver('cache', ['adapter' => $this->CI->config->item('cache_adapter'), 'backup' => $this->CI->config->item('cache_backup')]); // 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 ef5964468..70fddd0c4 100644 --- a/application/models/Dxcluster_model.php +++ b/application/models/Dxcluster_model.php @@ -53,7 +53,7 @@ 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', array('adapter' => 'file', 'backup' => 'file')); + $this->load->driver('cache', ['adapter' => $this->config->item('cache_adapter'), 'backup' => $this->config->item('cache_backup')]); // 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 c2ce9f40c..f2e2d1334 100644 --- a/application/models/Logbook_model.php +++ b/application/models/Logbook_model.php @@ -2716,7 +2716,7 @@ 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', array('adapter' => 'file', 'backup' => 'file')); + $this->load->driver('cache', ['adapter' => $this->config->item('cache_adapter'), 'backup' => $this->config->item('cache_backup')]); } // Cache TTL in seconds (15 minutes = 900 seconds) diff --git a/src/Dxcc/Dxcc.php b/src/Dxcc/Dxcc.php index 78b66452a..e3328d0a3 100644 --- a/src/Dxcc/Dxcc.php +++ b/src/Dxcc/Dxcc.php @@ -323,7 +323,7 @@ class Dxcc { */ function read_data($date = NULL) { $CI = &get_instance(); - $CI->load->driver('cache', ['adapter' => 'file']); + $CI->load->driver('cache', ['adapter' => $CI->config->item('cache_adapter'), 'backup' => $CI->config->item('cache_backup')]); // DXCC Exceptions $cache_key = 'dxcc_exceptions_' . ($date ?? 'all');