diff --git a/src/Core/Cache.php b/src/Core/Cache.php new file mode 100644 index 0000000000..21088a20a8 --- /dev/null +++ b/src/Core/Cache.php @@ -0,0 +1,61 @@ +. +// }}} + +namespace App\Core\Cache; + +use Functional as F; +use Symfony\Component\Cache\Adapter\AbstractAdapter; +use Symfony\Component\Cache\Adapter\ChainAdapter; + +abstract class Cache +{ + protected static AbstractAdapter $pool; + private const ENV_VAR = 'SOCIAL_CACHE_ADAPTER'; + + /** + * Configure a cache pool, with adapters taken from `ENV_VAR`. + * We may want multiple of these in the future, but for now it seems + * unnecessary + */ + public static function setPool() + { + if (!isset($_ENV[ENV_VAR])) { + return; + } + + $adapters = F\map(explode(':', strtolower($_ENV[ENV_VAR])), + function (string $a) { + return 'Adapter\\' . ucfirst($a) . 'Adapter'; + }); + + if (count($adapters) === 1) { + self::$pool = new $adapters[0]; + } else { + self::$pool = new ChainAdapter($adapters); + } + } + + /** + * Forward calls to the configured $pool + */ + public static function __callStatic(string $name, array $args) + { + return self::$pool->{$name}(...$args); + } +} diff --git a/src/Core/GNUsocial.php b/src/Core/GNUsocial.php index 3335d5db28..896c11a663 100644 --- a/src/Core/GNUsocial.php +++ b/src/Core/GNUsocial.php @@ -99,6 +99,7 @@ class GNUsocial implements EventSubscriberInterface Form::setFactory($this->form_factory); Queue::setMessageBus($this->message_bus); + Cache::setPool(); DefaultSettings::setDefaults(); ModulesManager::loadModules(); }