Skip to content

Commit

Permalink
Add caching to /tours API calls [MA-159]
Browse files Browse the repository at this point in the history
  • Loading branch information
nikhiltri committed Feb 26, 2024
1 parent 8be43a0 commit d16c2a0
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion app/Http/Controllers/Api/Tours.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@
use App\Repositories\Serializers\TourSerializer;
use App\Repositories\TourRepository;
use Illuminate\Support\Facades\App;
use Illuminate\Support\Facades\Cache;

class Tours extends Controller
{
public function __invoke()
{
$repository = App::make(TourRepository::class);
$tours = $repository->getBaseModel()->newQuery()->visible()->published()->get();
$tours = Cache::remember('tourRepo-all', 300, function () use ($repository) { return $repository->getBaseModel()->newQuery()->visible()->published()->get(); });
$serializer = new TourSerializer();
return $serializer->serialize($tours);
}
Expand Down

0 comments on commit d16c2a0

Please sign in to comment.