swoft框架通用缓存组件,基于swoft框架的aop实现
'redis' => [
'class' => RedisDb::class,
'host' => env("REDIS_HOST"),
'port' => env("REDIS_PORT"),
'database' => env("REDIS_DATABASE"),
'retryInterval' => 10,
'readTimeout' => 0,
'timeout' => 2,
'password' => env("REDIS_PASSWORD"),
'driver' => 'phpredis',
'option' => [
'prefix' => 'swoft_app_name',
'serializer' => Redis::SERIALIZER_NONE,
],
],
'redis.pool' => [
'class' => \Swoft\Redis\Pool::class,
'redisDb' => \bean('redis'),
'minActive' => 10,
'maxActive' => 20,
'maxWait' => 0,
'maxWaitTime' => 0,
'maxIdleTime' => 60,
]
use alan\swoft_cache_proxy\Annotation\Mapping\Cache;
use alan\swoft_cache_proxy\Helper\CacheRspHelper;
/**
* @Cache(isQuery=true)
* @return array
*/
public function testQuery() {
$cacheFlagValue = 123;
$now = time(); //业务代码
return CacheRspHelper::makeRsp(['now' => $now], $cacheFlagValue);
}
/**
* @Cache(isQuery=false)
* @return array
*/
public function testUpdate() {
//... 业务上的更新操作
$data = []; //业务操作返回
return CacheRspHelper::makeRsp($data, $cacheFlagValue);
}