To view the buff/cache:
free -h

To clean the buff/cache:
echo 1 > /proc/sys/vm/drop_caches
echo 2 > /proc/sys/vm/drop_caches
sync && echo 3 > /proc/sys/vm/drop_caches
You can put these shell commands in a script and run it in schedule with crontab:
Firstly, create script named clean.sh.
#!/bin/bash
echo 1 > /proc/sys/vm/drop_caches
echo 2 > /proc/sys/vm/drop_caches
sync && echo 3 > /proc/sys/vm/drop_caches
Secondly, run the script with crontab.
# Run commands go into editor mode.
crontab -e
# Enter editor mode and input below content with vim command.
# Execute once every 4 hours.
0 */2 * * * sh /your/path/clean.sh
# View the script if it exists or not.
crontab -l
# Clean the script if exist.
crontab -r