From aaba304ca88c89775bdf6df44a308965672d10d9 Mon Sep 17 00:00:00 2001 From: Hugo Sales Date: Fri, 10 Jul 2020 13:13:53 +0000 Subject: [PATCH] [CACHE][WRAPPER] Fix cache wrapper --- src/Core/Cache.php | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/src/Core/Cache.php b/src/Core/Cache.php index 21088a20a8..b743c3bd9b 100644 --- a/src/Core/Cache.php +++ b/src/Core/Cache.php @@ -17,7 +17,7 @@ // along with GNU social. If not, see . // }}} -namespace App\Core\Cache; +namespace App\Core; use Functional as F; use Symfony\Component\Cache\Adapter\AbstractAdapter; @@ -26,7 +26,7 @@ use Symfony\Component\Cache\Adapter\ChainAdapter; abstract class Cache { protected static AbstractAdapter $pool; - private const ENV_VAR = 'SOCIAL_CACHE_ADAPTER'; + private static string $ENV_VAR = 'SOCIAL_CACHE_ADAPTER'; /** * Configure a cache pool, with adapters taken from `ENV_VAR`. @@ -35,11 +35,11 @@ abstract class Cache */ public static function setPool() { - if (!isset($_ENV[ENV_VAR])) { + if (!isset($_ENV[self::$ENV_VAR])) { return; } - $adapters = F\map(explode(':', strtolower($_ENV[ENV_VAR])), + $adapters = F\map(explode(':', strtolower($_ENV[self::$ENV_VAR])), function (string $a) { return 'Adapter\\' . ucfirst($a) . 'Adapter'; }); @@ -51,11 +51,23 @@ abstract class Cache } } - /** - * Forward calls to the configured $pool - */ - public static function __callStatic(string $name, array $args) + public static function get(string $key, callable $calculate, float $beta = 1.0) { - return self::$pool->{$name}(...$args); + return self::$pool->get($key, $calculate, $beta); + } + + public static function delete(string $key) + { + return self::$pool->delete($key); + } + + public static function getList(string $key, callable $calculate, int $max_count = 0, float $beta = 1.0) + { + // Get the current keys associated with a list. If the cache + // is not primed, the function is called and returns an empty + // list + $keys = self::get($key, function (ItemInterface $i) { return []; }, $beta); + if ($max_count == 0) { + } } }