diff --git a/wp-includes/class-wp-theme.php b/wp-includes/class-wp-theme.php
index 171d8b6..b2331e1 100644
--- a/wp-includes/class-wp-theme.php
+++ b/wp-includes/class-wp-theme.php
@@ -985,10 +985,14 @@ final class WP_Theme implements ArrayAccess {
 	 */
 	public function get_files( $type = null, $depth = 0, $search_parent = false ) {
 		// get and cache all theme files to start with.
-		$label = sanitize_key( 'files_' . $this->cache_hash . '-' . $this->get( 'Version' ) );
-		$transient_key = substr( $label, 0, 29 ) . md5( $label );
+		$transient_key = $this->get_files_transient_key();
+
+		$all_files = false;
+
+		if ( ! WP_DEBUG ) {
+			$all_files = get_transient( $transient_key );
+		}
 
-		$all_files = get_transient( $transient_key );
 		if ( false === $all_files ) {
 			$all_files = (array) self::scandir( $this->get_stylesheet_directory(), null, -1 );
 
@@ -996,7 +1000,9 @@ final class WP_Theme implements ArrayAccess {
 				$all_files += (array) self::scandir( $this->get_template_directory(), null, -1 );
 			}
 
-			set_transient( $transient_key, $all_files, HOUR_IN_SECONDS );
+			if ( ! WP_DEBUG ) {
+				set_transient( $transient_key, $all_files, HOUR_IN_SECONDS );
+			}
 		}
 
 		// Filter $all_files by $type & $depth.
@@ -1110,6 +1116,18 @@ final class WP_Theme implements ArrayAccess {
 	}
 
 	/**
+	 * Clear the cache of files in the theme's directory.
+	 *
+	 * @since 4.9.1
+	 *
+	 * @return bool True if successful, false otherwise.
+	 */
+	public function flush_files_cache() {
+		$transient_key = $this->get_files_transient_key();
+		return delete_transient( $transient_key );
+	}
+
+	/**
 	 * Scans a directory for files of a certain extension.
 	 *
 	 * @since 3.4.0
@@ -1495,4 +1513,15 @@ final class WP_Theme implements ArrayAccess {
 		// Don't mark up; Do translate.
 		return strnatcasecmp( $a->display( 'Name', false, true ), $b->display( 'Name', false, true ) );
 	}
+
+	/**
+	 * Return a transient key used to cache the files in the theme's directory
+	 *
+	 * @since 4.9.1
+	 * @return string The transient key used into WP_Theme::get_files.
+	 */
+	private function get_files_transient_key() {
+		$label = sanitize_key( 'files_' . $this->cache_hash . '-' . $this->get( 'Version' ) );
+		return substr( $label, 0, 29 ) . md5( $label );
+	}
 }
