• New Feature
  • Status: Closed
  • 2 Major
  • Resolution: Fixed
  • hsingh
  • Reporter:
  • September 21, 2009
  • 0
  • Watchers: 0
  • January 17, 2013
  • December 07, 2009

Description

We use multiple databases and prefix our caches using the hibernate.cache.region_prefix property. I was looking for a quick way to clear all caches for a specific region and this is what I came up with. It’d be nice to see this added to the CacheManager object, as I’m sure a number of people could use it.

public void clearCacheByRegionPrefix(String regionPrefix) {

    String[] cacheNames = getCacheNames();
    for (int i = 0; i < cacheNames.length; i++) {
        String cacheName = cacheNames[i];
        if (cacheName.startsWith(regionPrefix)) {
            Ehcache cache = cacheManager.getEhcache(cacheName);
            cache.removeAll();
    }

Sourceforge Ticket ID: 1965445 - Opened By: nobody - 16 May 2008 15:43 UTC

Comments

Steve Harris 2009-10-13

Look into whether we should use a pattern and also should this go in the operations console.

Alexander Snaps 2009-12-07

The current impl. matches other CacheManager behaviors, but I think it might require some reviewing: returning silently on null or empty string prefix

Himadri Singh 2009-12-15

Verified with

product-name = Ehcache Core version = 1.7.2 built-by = cruise build-jdk = 1.6.0_17 build-time = 2009-12-12 03:48:03 build-revision = 1516

Wrote a small test:

Putting 10 elements in all three caches: dummy, dummyTwo, NotDummy dummy:10 dummyTwo:10 NotDummy:10

Clearing cache starting with dummy dummy:0 dummyTwo:0 NotDummy:10