Hibernate 2nd level cache invalidation when another process modifies the database

前端 未结 6 1140
[愿得一人]
[愿得一人] 2020-12-07 19:16

We have an application that uses Hibernate\'s 2nd level caching to avoid database hits.

I was wondering if there is some easy way to invalidate the Java application

6条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-07 19:41

    I was searching how to invalidate all Hibernate caches and I found this useful snippet:

    sessionFactory.getCache().evictQueryRegions();
    sessionFactory.getCache().evictDefaultQueryRegion();
    sessionFactory.getCache().evictCollectionRegions();
    sessionFactory.getCache().evictEntityRegions();
    

    Hope it helps to someone else.

提交回复
热议问题