Hyperf框架 - 缓存Cache操作

编写Cache代理类


	/**
	* ----------------------------------------------------------
	* date: 2020/7/22 17:07
	* ----------------------------------------------------------
	* author: Raoxiaoya
	* ----------------------------------------------------------
	* describe:
	* ----------------------------------------------------------
	*/

	namespace App\Utils;


	use Hyperf\Utils\ApplicationContext;
	use Psr\SimpleCache\CacheInterface;

	class Cache
	{
		public static function getInstance()
		{
			return ApplicationContext::getContainer()->get(CacheInterface::class);
		}

		public static function __callStatic($name, $arguments)
		{
			return self::getInstance()->$name(...$arguments);
		}
	}

使用

Cache::getInstance()->set('test', ['name'=>'123', 'age'=>'123']);
$re = Cache::get('test');
var_dump($re);

你可能感兴趣的:(#,swoole)