Skip to content

Commit 0ba9a3a

Browse files
committed
HHH-7150 added Cache#evictAllRegions
1 parent 4a898c5 commit 0ba9a3a

File tree

4 files changed

+16
-5
lines changed

4 files changed

+16
-5
lines changed

hibernate-core/src/main/java/org/hibernate/Cache.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,4 +185,9 @@ public interface Cache {
185185
* Evict data from all query regions.
186186
*/
187187
public void evictQueryRegions();
188+
189+
/**
190+
* Evict all data from the cache.
191+
*/
192+
public void evictAllRegions();
188193
}

hibernate-core/src/main/java/org/hibernate/internal/CacheImpl.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,4 +354,13 @@ public Map<String, Region> getAllSecondLevelCacheRegions() {
354354
public RegionFactory getRegionFactory() {
355355
return regionFactory;
356356
}
357+
358+
@Override
359+
public void evictAllRegions() {
360+
evictCollectionRegions();
361+
evictDefaultQueryRegion();
362+
evictEntityRegions();
363+
evictQueryRegions();
364+
evictNaturalIdRegions();
365+
}
357366
}

hibernate-entitymanager/src/main/java/org/hibernate/jpa/internal/EntityManagerFactoryImpl.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -557,6 +557,7 @@ public void evict(Class entityClass) {
557557
}
558558

559559
public void evictAll() {
560+
// Evict only the "JPA cache", which is purely defined as the entity regions.
560561
sessionFactory.getCache().evictEntityRegions();
561562
// TODO : if we want to allow an optional clearing of all cache data, the additional calls would be:
562563
// sessionFactory.getCache().evictCollectionRegions();

hibernate-testing/src/main/java/org/hibernate/testing/junit4/BaseCoreFunctionalTestCase.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -441,11 +441,7 @@ public final void afterTest() throws Exception {
441441

442442
protected void cleanupCache() {
443443
if ( sessionFactory != null ) {
444-
sessionFactory.getCache().evictCollectionRegions();
445-
sessionFactory.getCache().evictDefaultQueryRegion();
446-
sessionFactory.getCache().evictEntityRegions();
447-
sessionFactory.getCache().evictQueryRegions();
448-
sessionFactory.getCache().evictNaturalIdRegions();
444+
sessionFactory.getCache().evictAllRegions();
449445
}
450446
}
451447

0 commit comments

Comments
 (0)