Mathieu Hays

I’m using WP Super Cache for most of my page caching needs. All pages on my website are cached on disk so they load faster. In order to avoid caching issues when deploying a new version, I always make sure to empty the cache folder. I do this by excluding all files in the cache folder and only keep a file called .gitkeep (could be any name but this one is a standard).

# .gitignore file


Because WP Super Cache runs a function that cleans the cache folder from any file that shouldn’t be there, I often ended up deploying without the cache folder (because the .gitkeep file went missing). This could be an issue depending on the permissions you set on your web server.

To prevent the plugin from removing the .gitkeep file, I submitted an issue to the author of the plugin which then added the filter below. Adding this to your installation will prevent the plugin from removing any file you add there.

add_filter( 'wpsc_get_protected_directories', function( $paths ) {
    global $cache_path;

    $paths[] = $cache_path . '.gitkeep';

    return $paths;