Commit 65226667 by 杨树贤

设置缓存

parent 12f4aeec
......@@ -25,5 +25,5 @@ REDIS_READ_HOST=192.168.1.235
REDIS_READ_PASSWORD=icDb29mLy2s
REDIS_READ_PORT=6379
CACHE_DRIVER=file
CACHE_DRIVER=redis
QUEUE_DRIVER=sync
......@@ -6,17 +6,20 @@ namespace App\Services;
use App\Model\ArctypeModel;
use App\Model\ArticleModel;
use Illuminate\Support\Facades\Cache;
class FaqService extends BaseService
{
public function getFaqList()
{
$model = new ArctypeModel();
//获取所有faq相关的文章,50应该差不多了
$list = $model->getFaqList();
$list = $this->transform($list);
return $list;
return Cache::remember('faqListCache', 5, function () {
$model = new ArctypeModel();
//获取所有faq相关的文章,50应该差不多了
$list = $model->getFaqList();
$list = $this->transform($list);
return $list;
});
}
......@@ -34,11 +37,13 @@ class FaqService extends BaseService
public function getFaq($id)
{
$model = new ArticleModel();
$faq = $model->getFaq($id);
$faq = $this->transformFaq($faq);
return Cache::remember('faqCache_' . $id, 5, function () use ($id) {
$model = new ArticleModel();
$faq = $model->getFaq($id);
$faq = $this->transformFaq($faq);
return $faq;
return $faq;
});
}
private function transformFaq($data)
......
......@@ -6,17 +6,20 @@ namespace App\Services;
use App\Model\ArctypeModel;
use App\Model\ArticleModel;
use Illuminate\Support\Facades\Cache;
class NoticeService extends BaseService
{
public function getNoticeList($page,$pageSize)
public function getNoticeList($page, $pageSize)
{
$model = new ArticleModel();
//获取所有faq相关的文章,50应该差不多了
$list = $model->getNoticeList($page,$pageSize);
$list = $this->transform($list);
return $list;
return Cache::remember("noticeListCache_$page"."_$pageSize", 5, function () use ($page, $pageSize) {
$model = new ArticleModel();
//获取所有faq相关的文章,50应该差不多了
$list = $model->getNoticeList($page, $pageSize);
$list = $this->transform($list);
return $list;
});
}
......@@ -33,11 +36,13 @@ class NoticeService extends BaseService
public function getNotice($id)
{
$model = new ArticleModel();
$faq = $model->getNotice($id);
$faq = $this->transformNotice($faq);
return Cache::remember('noticeCache_' . $id, 5, function () use ($id) {
$model = new ArticleModel();
$faq = $model->getNotice($id);
$faq = $this->transformNotice($faq);
return $faq;
return $faq;
});
}
private function transformNotice($data)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment