From 8e0303f0659fa65319910bc52a87dda470e5db1e Mon Sep 17 00:00:00 2001 From: the-djmaze <> Date: Sun, 31 Mar 2024 21:06:39 +0200 Subject: [PATCH] Resolve #1533 --- plugins/cache-apcu/index.php | 34 +++++++++++++++++++ plugins/cache-memcache/index.php | 54 +++++++++++++++++++++++++++++ plugins/cache-redis/index.php | 58 ++++++++++++++++++++++++++++++++ 3 files changed, 146 insertions(+) create mode 100644 plugins/cache-apcu/index.php create mode 100644 plugins/cache-memcache/index.php create mode 100644 plugins/cache-redis/index.php diff --git a/plugins/cache-apcu/index.php b/plugins/cache-apcu/index.php new file mode 100644 index 000000000..2e17413a4 --- /dev/null +++ b/plugins/cache-apcu/index.php @@ -0,0 +1,34 @@ +addHook('main.fabrica', 'MainFabrica'); + } + } + + public function Supported() : string + { + return \MailSo\Base\Utils::FunctionsCallable(array('apcu_store', 'apcu_fetch', 'apcu_delete', 'apcu_clear_cache')) + ? '' + : 'PHP APCu not installed'; + } + + public function MainFabrica($sName, &$mResult) + { + if ('cache' == $sName) { + require_once __DIR__ . '/APCU.php'; + $mResult = new \MailSo\Cache\Drivers\APCU; + } + } +} diff --git a/plugins/cache-memcache/index.php b/plugins/cache-memcache/index.php new file mode 100644 index 000000000..6a7354e13 --- /dev/null +++ b/plugins/cache-memcache/index.php @@ -0,0 +1,54 @@ +addHook('main.fabrica', 'MainFabrica'); + } + } + + public function Supported() : string + { + return (\class_exists('Memcache',false) || \class_exists('Memcached',false)) + ? '' + : 'PHP Memcache/Memcached not installed'; + } + + public function MainFabrica($sName, &$mResult) + { + if ('cache' == $sName) { + require_once __DIR__ . '/Memcache.php'; + $mResult = new \MailSo\Cache\Drivers\Memcache( + $this->Config()->Get('plugin', 'host', '127.0.0.1'), + (int) $this->Config()->Get('plugin', 'port', 11211) + ); + } + } + + protected function configMapping() : array + { + return array( + \RainLoop\Plugins\Property::NewInstance('host')->SetLabel('Host') + ->SetDescription('Hostname of the memcache server') + ->SetDefaultValue('127.0.0.1'), + \RainLoop\Plugins\Property::NewInstance('port')->SetLabel('Port') + ->SetDescription('Port of the memcache server') + ->SetDefaultValue(11211) +/* + ,\RainLoop\Plugins\Property::NewInstance('password')->SetLabel('Password') + ->SetType(\RainLoop\Enumerations\PluginPropertyType::PASSWORD) + ->SetDefaultValue('') +*/ + ); + } +} diff --git a/plugins/cache-redis/index.php b/plugins/cache-redis/index.php new file mode 100644 index 000000000..a04828bbc --- /dev/null +++ b/plugins/cache-redis/index.php @@ -0,0 +1,58 @@ +addHook('main.fabrica', 'MainFabrica'); + } + } + + public function Supported() : string + { + return ''; + } + + public function MainFabrica($sName, &$mResult) + { + if ('cache' == $sName) { + require_once __DIR__ . '/Redis.php'; + $mResult = new \MailSo\Cache\Drivers\Redis( + $this->Config()->Get('plugin', 'host', '127.0.0.1'), + (int) $this->Config()->Get('plugin', 'port', 6379) + ); + } + } + + protected function configMapping() : array + { + return array( + \RainLoop\Plugins\Property::NewInstance('host')->SetLabel('Host') + ->SetDescription('Hostname of the redis server') + ->SetDefaultValue('127.0.0.1'), + \RainLoop\Plugins\Property::NewInstance('port')->SetLabel('Port') + ->SetDescription('Port of the redis server') + ->SetDefaultValue(6379) +/* + ,\RainLoop\Plugins\Property::NewInstance('password')->SetLabel('Password') + ->SetType(\RainLoop\Enumerations\PluginPropertyType::PASSWORD) + ->SetDefaultValue('') +*/ + ); + } +}