/**
  * Clear the cache for a given database result and return the number of affected files.
  *
  * @param Result $result The database result.
  *
  * @return int
  */
 private function clearCache($result)
 {
     $delete = array();
     while ($result->next()) {
         $cacheFile = sprintf('system/cache/html/%s/%s.html', substr($result->cacheKey, 0, 1), $result->cacheKey);
         $this->fileSystem->delete($cacheFile);
         $delete[] = $result->id;
     }
     if ($delete) {
         $result = $this->database->execute(Query::removeEntries($delete));
         return $result->affectedRows;
     }
     return 0;
 }