# remove all cached versions of uninstalled packages
sudo paccache -ruk0
# remove all uninstalled packages
sudo pacman -Sc
# completely remove all packages from the cache
sudo pacman -Scc
# the package cache will be cleaned automatically after every pacman transactions (like upgrade, install, remove)
sudo mkdir /etc/pacman.d/hooks
sudo nano /etc/pacman.d/hooks/clean_package_cache.hook
# add
[Trigger]
Operation = Upgrade
Operation = Install
Operation = Remove
Type = Package
Target = *
[Action]
Description = Cleaning pacman cache...
When = PostTransaction
Exec = /usr/bin/paccache -r