Caching added for api
This commit is contained in:
@@ -8,6 +8,7 @@ use App\Http\Resources\TopicResource;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use App\Http\Resources\ArticleResource;
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
|
||||
class TopicsAPIController extends Controller
|
||||
{
|
||||
@@ -21,7 +22,7 @@ class TopicsAPIController extends Controller
|
||||
{
|
||||
return TopicResource::collection(Topic::inRandomOrder()->take(12)->get());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Load all the articles for a given topics
|
||||
*
|
||||
@@ -29,9 +30,11 @@ class TopicsAPIController extends Controller
|
||||
*/
|
||||
public function show(Topic $topic)
|
||||
{
|
||||
return response()->json([
|
||||
'topic' => new TopicResource($topic),
|
||||
'articles' => $topic->articles()->with('source')->latest('published_date')->paginate(8)
|
||||
]);
|
||||
return Cache::remember('topic_'.$topic->slug, 300, function () use ($topic) {
|
||||
return response()->json([
|
||||
'topic' => new TopicResource($topic),
|
||||
'articles' => $topic->articles()->with('source')->latest('published_date')->paginate(8)
|
||||
]);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user