How to clear all Hibernate cache (ehcache) using Spring?

前端 未结 7 1412
长情又很酷
长情又很酷 2020-12-14 01:44

I am using 2nd level cache and query cache. May I know how to programmatically clear all caches ?

7条回答
  •  鱼传尺愫
    2020-12-14 02:29

    Same as @Dino's answer, shortened syntax for JPA 2.0 API:

    @Autowired
    private EntityManagerFactory entityManagerFactory;
    
    public void clearHibernateCaches() {
        entityManagerFactory.getCache().unwrap(org.hibernate.Cache.class).evictAllRegions();
    }
    

提交回复
热议问题