500 server errors randomly clearcache fixes

I have been using grav for a personal site for the past year or so without any real issues. I have a fairly vanilla set up, just a lightly modified “minimaxing” theme that I found and changed some colors. Things had been great running on my old rasberry pi. A few months ago I moved the server to a new box to reclaim my rasberry pi for something else. The site works great normally, but I have noticed that randomly I will start getting 500 server errors. running the following fixes the issue and the site works normally

`bin/grav clearcache`

However the fix only stays good for a random amount of time. Sometime 15 min, sometimes 15 days. Included below is an entry (website name changed to “mysite.com” to not appear to be self promoting) in the apache log file when the server is delivering a 500 error

`[Sun Dec 27 02:06:07.051904 2020] [php7:error] [pid 30170] [client] PHP Fatal error:  Uncaught RuntimeException: Failed to save file /var/www/mysite.com/public_html/cache/compiled/blueprints/master- in /var/www/mysite.com/public_html/vendor/rockettheme/toolbox/File/src/File.php:351\nStack trace:\n#0 /var/www/mysite.com/public_html/vendor/rockettheme/toolbox/File/src/PhpFile.php(31): RocketTheme\\Toolbox\\File\\File->save(Array)\n#1 /var/www/mysite.com/public_html/system/src/Grav/Common/Config/CompiledBase.php(252): RocketTheme\\Toolbox\\File\\PhpFile->save(Array)\n#2 /var/www/mysite.com/public_html/system/src/Grav/Common/Config/CompiledBase.php(117): Grav\\Common\\Config\\CompiledBase->saveCompiledFile('/var/www/mysite...')\n#3 /var/www/mysite.com/public_html/system/src/Grav/Common/Service/ConfigServiceProvider.php(77): Grav\\Common\\Config\\CompiledBase->load()\n#4 /var/www/mysite.com/public_html/system/src/Grav/Common/Service/ConfigServiceProvider.php(36): Grav\\Common\\Service\\ConfigServiceProvider::blueprints(Object(Grav\\Common\\Grav))\n#5 /var/www/mysite.com/public_html/vendor/pimple/pimple/sr in /var/www/mysite.com/public_html/vendor/rockettheme/toolbox/File/src/File.php on line 351`

I have checked permissions on the cache folder and they look good:

`drwxr-xr-x 7 www-data www-data 4096 Dec 27 07:19 /var/www/mysite.com/public_html/cache/`

Any ideas on what is going on and what I can do to not have my site go inaccessible all the time?

I noticed that I had the grav scheduler in both root and the apache user’s crontab somehow. I removed it from root and hopefully that will fix the issue.