log("Cache info:\n" // . 'Cache driver: redis' . "\n" // . '├ Redis host: ' . $host . "\n" // . '├ Redis port: ' . $port . "\n" // . '├ Redis password: ' . str_repeat('*', strlen($password)) . "\n" // . '└ Redis database: ' . $database . "\n" // ); return new RedisCacheDriver( $config['cache']['prefix'], $host, $port, $password, $database ); case 'apcu': return new ApcuCacheDriver; case 'fs': return new FsCacheDriver( $config['cache']['prefix'], "tmp/cache/{$config['cache']['prefix']}", '.lock', $config['auto_maintenance'] ? 1000 : false ); case 'none': return new NoneCacheDriver(); case 'php': default: return new ArrayCacheDriver(); } } public static function getCache(): CacheDriver { static $cache; return $cache ??= self::buildCache(); } public static function get($key) { global $config, $debug; $ret = self::getCache()->get($key); if ($ret === null) { $ret = false; } if ($config['debug']) { $debug['cached'][] = $config['cache']['prefix'] . $key . ($ret === false ? ' (miss)' : ' (hit)'); } return $ret; } public static function set($key, $value, $expires = false) { global $config, $debug; if (!$expires) { $expires = $config['cache']['timeout']; } self::getCache()->set($key, $value, $expires); if ($config['debug']) { $debug['cached'][] = $config['cache']['prefix'] . $key . ' (set)'; } } public static function delete($key) { global $config, $debug; self::getCache()->delete($key); if ($config['debug']) { $debug['cached'][] = $config['cache']['prefix'] . $key . ' (deleted)'; } } public static function flush() { self::getCache()->flush(); return false; } }