Unlink cache warnings in SS5.2 and 4.13

Silverstripe Version: 5.2 and 4.13

Question:

I’m getting lot of warnings with the following pattern:

[2024-07-25 11:22:46] error-log.WARNING: E_WARNING: unlink(/tmp/silverstripe-cache-php8.1.28-var-www-html/username/.cachethemes.source_unify.src.templates.Includes.Footer.ss): No such file or directory {"code":2,"message":"unlink(/tmp/silverstripe-cache-php8.1.28-var-www-html/username/.cachethemes.source_unify.src.templates.Includes.Footer.ss): No such file or directory","file":"/var/www/html/vendor/silverstripe/framework/src/View/SSViewer.php","line":514} []

This is then followed by:

[2024-07-25 11:22:46] error-log.WARNING: E_USER_WARNING: Couldn't set response type to 404 because of output on line 427 of /var/www/html/vendor/silverstripe/framework/src/Control/HTTPResponse.php {"code":512,"message":"Couldn't set response type to 404 because of output on line 427 of /var/www/html/vendor/silverstripe/framework/src/Control/HTTPResponse.php","file":"/var/www/html/vendor/silverstripe/framework/src/Control/HTTPResponse.php","line":405} []

They appear when the website is navigated, often after a page is refreshed, especially when some page components such as images didn’t display on first load. I cannot work out what is causing this or how to fix it. I didn’t used to get errors like this and they seem to be increasing the more the website is used.

Is this due to the cache not being cleared properly or is it the result of a recent SS upgrade?

I’m using DDEV for my local testing environment.

Any help or suggestions most welcome!

Turns out I’d added the following in my _config.php while previously upgrading SS / php (to avoid the white screen of death):

if (Director::isDev() || Director::isTest()) {
    ini_set('display_errors', 1);
    error_reporting(E_ALL);
    SSViewer::flush_template_cache();
}

Well doh - of course SSViewer::flush_template_cache(); is going to cause the cache files to disappear… I commented that line out and the errors disappeared.

Hopefully this will be helpful to someone else!