cancel
Showing results forย 
Search instead forย 
Did you mean:ย 
Data Engineering
Join discussions on data engineering best practices, architectures, and optimization strategies within the Databricks Community. Exchange insights and solutions with fellow data engineers.
cancel
Showing results forย 
Search instead forย 
Did you mean:ย 

How to clear all cache without restarting the cluster?

shan_chandra
Databricks Employee
Databricks Employee
 
1 ACCEPTED SOLUTION

Accepted Solutions

shan_chandra
Databricks Employee
Databricks Employee
%scala
def clearAllCaching(tableName: Option[String] = None): Unit = {
tableName.map { path =>
com.databricks.sql.transaction.tahoe.DeltaValidation.invalidateCache(spark, path)
}
spark.conf.set("com.databricks.sql.io.caching.bucketedRead.enabled", "false")
spark.conf.set("spark.databricks.delta.smallTable.cache.enabled", "false")
spark.conf.set("spark.databricks.delta.stats.localCache.maxNumFiles", "1")
spark.conf.set("spark.databricks.delta.fastQueryPath.dataskipping.checkpointCache.enabled", "false")
spark.conf.set("spark.databricks.io.cache.enabled", "false")
com.databricks.sql.transaction.tahoe.DeltaLog.clearCache()
spark.sql("CLEAR CACHE")
sqlContext.clearCache()  
}

Please find the above piece of custom method to clear all the cache in the cluster without restarting . This will clear the cache by invoking the method given below.

%scala clearAllCaching()

The cache can be validated in the SPARK UI -> storage tab in the cluster.

View solution in original post

2 REPLIES 2

shan_chandra
Databricks Employee
Databricks Employee
%scala
def clearAllCaching(tableName: Option[String] = None): Unit = {
tableName.map { path =>
com.databricks.sql.transaction.tahoe.DeltaValidation.invalidateCache(spark, path)
}
spark.conf.set("com.databricks.sql.io.caching.bucketedRead.enabled", "false")
spark.conf.set("spark.databricks.delta.smallTable.cache.enabled", "false")
spark.conf.set("spark.databricks.delta.stats.localCache.maxNumFiles", "1")
spark.conf.set("spark.databricks.delta.fastQueryPath.dataskipping.checkpointCache.enabled", "false")
spark.conf.set("spark.databricks.io.cache.enabled", "false")
com.databricks.sql.transaction.tahoe.DeltaLog.clearCache()
spark.sql("CLEAR CACHE")
sqlContext.clearCache()  
}

Please find the above piece of custom method to clear all the cache in the cluster without restarting . This will clear the cache by invoking the method given below.

%scala clearAllCaching()

The cache can be validated in the SPARK UI -> storage tab in the cluster.

Hubert-Dudek
Esteemed Contributor III

Great. You can add โ€‹ spark.catalog.clearCache() as well.

Connect with Databricks Users in Your Area

Join a Regional User Group to connect with local Databricks users. Events will be happening in your city, and you wonโ€™t want to miss the chance to attend and share knowledge.

If there isnโ€™t a group near you, start one and help create a community that brings people together.

Request a New Group