我需要在队列中设置缓存,在我的清单中,我从缓存中获取产品类别计数,缓存每24小时就会重置一次,但是我有600万以上的产品,因此每24小时该页面需要花费太多时间获取计数,因此,如果缓存时间已过,则需要运行队列并从缓存中获取数据问题是需要在队列中调用回调函数
这是我的代码
这是控制者
$DBConditions = Cache::get($cacheKey, function () {
return $this->getProductCategoty();
}, true,Cache::1_DAY_TIMEOUT,self::ASYNCVALUE);
This is my cache Helper
public static function get($key, $function, $cacheSession = false, $timeout = self::ONE_DAY,$Async = false)
{
$data = cache($key);
if (!isset($data)) {
if(!isset($defaultAsyncValue) || empty($defaultAsyncValue)){
dispatch(new CallCallback($key,$timeout,$function));
return array();
}
}
return $data;
}
This is my Queue handle
public function handle()
{
$data=array();
try {
$data = call_user_func($this->function); //This is my callback function
} catch (\Exception $e) {
self::logMessage('array:- '.print_r($e->getMessage(),true));
}
cache([$this->key => $data], $this->timeout);
}
Need to call that controller`s function to get data