Cache invalidation in Ehcache

后端 未结 5 1391
北恋
北恋 2020-12-19 09:03

I am using Ehcache in Hibernate.

How can I notify the cache that the database has changed? How can I invalidate the cached data? How can I programmatically achieve t

5条回答
  •  一整个雨季
    2020-12-19 09:53

    What do exactly mean? There are 2 ways to make a change in the database: inside the app & outside the app

    Inside the app you can trigger easily an invalidation. The second one is a harder to solve. Cache elements are stored with a key and based on that key you can delete it.

    CacheManager manager = CacheManager.getInstance();
    cache = manager.getCache(cacheName);
    cache.remove(key);
    
    or 
    
    cache.removeAll();
    

    Depending how you configured ehcache of course. But you need to know the name of the cache that holds the object.

提交回复
热议问题