Clearing System Cache
Clear the PageCache, dentries, and inodes
To free up the system cache, you can use the following commands:
sudo sync; sudo sysctl -w vm.drop_caches=3
Free up memory and cache
To clear the memory cache:
sudo sh -c "echo 3 > /proc/sys/vm/drop_caches"
Clearing Web Server Cache
For Apache:
Restart Apache to Clear the Cache
sudo systemctl restart apache2
Clear Specific Cache Directories (if used)
If you have set up specific cache directories in your Apache configuration, clear them manually:
sudo rm -rf /var/cache/apache2/*
For Nginx:
Restart Nginx to Clear the Cache
sudo systemctl restart nginx
Clear Specific Cache Directories (if used)
If you have set up specific cache directories in your Nginx configuration, clear them manually:
sudo rm -rf /var/cache/nginx/*
Clearing Application Cache (e.g., Laravel)
For Laravel:
Clear Laravel Cache Using Artisan Commands
Navigate to your Laravel project directory and run the following commands:
cd /path/to/your/laravel/project
php artisan cache:clear
php artisan config:clear
php artisan route:clear
php artisan view:clear
Clear Compiled Files
php artisan clear-compiled
Optimize Cache (optional)
php artisan optimize
Clearing PHP Cache
For OPCache:
Clear OPCache
Create a PHP file (e.g., clear_opcache.php) with the following content:
php
<?php
opcache_reset();
echo "OPCache has been reset.";
?>
Run this file by accessing it via your web browser:
http://your-ec2-instance-public-dns/clear_opcache.php
Remove the file after use
rm /path/to/your/laravel/public/clear_opcache.php
Clearing DNS Cache
For Ubuntu:
Install nscd (if not installed)
sudo apt-get install nscd
Clear DNS Cache
sudo systemctl restart nscd
0 More Answers