public static function clearPageCache() { //If a clear is in progress this does nothing. self::$cacheStats = array('dirsDeleted' => 0, 'filesDeleted' => 0, 'totalData' => 0, 'totalErrors' => 0, 'error' => ''); $cacheClearLock = WP_CONTENT_DIR . '/wfcache/clear.lock'; if (!is_file($cacheClearLock)) { if (!touch($cacheClearLock)) { self::$cacheStats['error'] = "Could not create a lock file {$cacheClearLock} to clear the cache."; self::$cacheStats['totalErrors']++; return self::$cacheStats; } } $fp = fopen($cacheClearLock, 'w'); if (!$fp) { self::$cacheStats['error'] = "Could not open the lock file {$cacheClearLock} to clear the cache. Please make sure the directory is writable by your web server."; self::$cacheStats['totalErrors']++; return self::$cacheStats; } if (flock($fp, LOCK_EX | LOCK_NB)) { //non blocking exclusive flock attempt. If we get a lock then it continues and returns true. If we don't lock, then return false, don't block and don't clear the cache. // This logic means that if a cache clear is currently in progress we don't try to clear the cache. // This prevents web server children from being queued up waiting to be able to also clear the cache. self::$lastRecursiveDeleteError = false; self::recursiveDelete(WP_CONTENT_DIR . '/wfcache/'); if (self::$lastRecursiveDeleteError) { self::$cacheStats['error'] = self::$lastRecursiveDeleteError; self::$cacheStats['totalErrors']++; } flock($fp, LOCK_UN); } fclose($fp); return self::$cacheStats; }
public static function clearPageCache() { //If a clear is in progress this does nothing. self::$cacheStats = array('dirsDeleted' => 0, 'filesDeleted' => 0, 'totalData' => 0, 'totalErrors' => 0); $cacheClearLock = WP_CONTENT_DIR . '/wfcache/clear.lock'; if (!is_file($cacheClearLock)) { touch($cacheClearLock); } $fp = fopen($cacheClearLock, 'w'); if (!$fp) { return; } if (flock($fp, LOCK_EX | LOCK_NB)) { //non blocking exclusive flock attempt. If we get a lock then it continues and returns true. If we don't lock, then return false, don't block and don't clear the cache. // This logic means that if a cache clear is currently in progress we don't try to clear the cache. // This prevents web server children from being queued up waiting to be able to also clear the cache. self::recursiveDelete(WP_CONTENT_DIR . '/wfcache/'); flock($fp, LOCK_UN); } fclose($fp); return self::$cacheStats; }