29 lines
878 B
PHP
Executable File
29 lines
878 B
PHP
Executable File
<?php
|
|
|
|
namespace App\Providers;
|
|
|
|
use Illuminate\Support\ServiceProvider;
|
|
use Illuminate\Support\Facades\View;
|
|
use Illuminate\Support\Facades\Cache;
|
|
use App\Services\CacheService;
|
|
//use App\Models\Categories;
|
|
|
|
class ArticleOrderLikesProvider extends ServiceProvider
|
|
{
|
|
public function boot(): void
|
|
{
|
|
// 只有渲染 components.order-likes 这个组件时,这段逻辑才会运行
|
|
View::composer('components.order-likes', function ($oView) {
|
|
// 从缓存拿数据,拿不到就触发一次更新(高标准兜底)
|
|
$aHotArticles = Cache::get(CacheService::CACHE_KEYS['article_order_likes']);
|
|
|
|
if (is_null($aHotArticles)) {
|
|
$aHotArticles = CacheService::updateOrderLikes();
|
|
}
|
|
|
|
$oView->with('oOrderLikes', $aHotArticles);
|
|
|
|
});
|
|
}
|
|
}
|