编写Cache代理类
<?php
/**
* ----------------------------------------------------------
* 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);