This Laravel application demonstrates how to implement task scheduling and caching for an API. It periodically cleans old API logs and caches responses from an external news API for faster retrieval.
- Scheduled task to delete logs older than 30 days.
- Caching of API responses using Redis.
- API endpoint to fetch cached news data.
- Logging of API requests to the database.
- PHP >= 8.0
- Composer
- Laravel 10
- MySQL or any other database
- Redis or Memcached (for caching)
Clone this repository to your local machine using the following command:
git clone https://github.com/Kayuztech/Task-Scheduling-Caching.git
cd TaskScheduling
composer install
cp .env.example .env
DB_CONNECTION=mysql DB_HOST=127.0.0.1 DB_PORT=3306 DB_DATABASE=your_database_name DB_USERNAME=your_database_user DB_PASSWORD=your_database_password
CACHE_DRIVER=redis SESSION_DRIVER=redis
php artisan key:generate
php artisan migrate
php artisan serve
Fetch News Data: Call the API endpoint to get the cached news data.
GET http://127.0.0.1:8000/api/news
View API Logs: To see the stored logs of API requests, you can query the apilogs table in your database.
Laravel WeatherAPI Redis