Automating Sitemap Updates on Deployment
The Problem
After each deployment to our production environment, we needed to manually clear the sitemap cache to ensure the latest content was reflected. This manual process was time-consuming and prone to errors.
The Approach
We automated the sitemap cache clearing process by creating a custom Artisan command that is executed as part of our deployment pipeline.
Implementation
We created a new Artisan command, seo:clear-cache, to handle the cache clearing.
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Cache;
class ClearSeoCache extends Command
{
protected $signature = 'seo:clear-cache';
protected $description = 'Clears the sitemap and showcase profile caches';
public function handle()
{
Cache::forget('sitemap');
Cache::forget('showcase_profiles');
$this->info('Sitemap and showcase profile caches cleared successfully!');
}
}
This command clears the sitemap and showcase_profiles keys from the cache. We then updated our deployment script to execute this command after each deployment. This ensures that the sitemap and showcase profiles are always generated with the latest data.
Deployment Integration
Our deployment script now includes the following command:
php artisan seo:clear-cache
This command is executed after the code is deployed, ensuring the cache is cleared before the new version goes live.
Key Insight
Automating tasks like cache clearing can significantly improve deployment efficiency and reduce the risk of human error. By integrating the seo:clear-cache command into our deployment process, we ensure that our sitemap is always up-to-date with minimal effort.