Caching added for api
This commit is contained in:
@@ -6,9 +6,10 @@ use App\Article;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Http\Resources\ArticleResource;
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
|
||||
final class RecentArticles extends Controller
|
||||
{
|
||||
{
|
||||
/**
|
||||
* Get the Latest articles made paginated
|
||||
*
|
||||
@@ -16,10 +17,12 @@ final class RecentArticles extends Controller
|
||||
*/
|
||||
public function __invoke()
|
||||
{
|
||||
return [
|
||||
"articles" => Article::with('source', 'topics')
|
||||
->latest("published_date")
|
||||
->paginate(20)
|
||||
];
|
||||
return Cache::remember('articles.recent', 300, function () {
|
||||
return [
|
||||
"articles" => Article::with('source', 'topics')
|
||||
->latest("published_date")
|
||||
->paginate(20)
|
||||
];
|
||||
});
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user