Java Code Examples for org.springframework.cache.CacheManager#getCacheNames()

The following examples show how to use org.springframework.cache.CacheManager#getCacheNames() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DateIndexHelper.java    From datawave with Apache License 2.0 6 votes vote down vote up
private void showMeDaCache(String when) {
    log.trace("from applicationContext:" + applicationContext);
    if (this.applicationContext != null) {
        CacheManager cacheManager = applicationContext.getBean("dateIndexHelperCacheManager", CacheManager.class);
        log.trace("beans are " + Arrays.toString(applicationContext.getBeanDefinitionNames()));
        if (cacheManager != null) {
            for (String cacheName : cacheManager.getCacheNames()) {
                log.trace(when + " got " + cacheName);
                Object nativeCache = cacheManager.getCache(cacheName).getNativeCache();
                log.trace("nativeCache is a " + nativeCache);
                Cache cache = (Cache) nativeCache;
                Map map = cache.asMap();
                log.trace("cache map is " + map);
                log.trace("cache map size is " + map.size());
                for (Object key : map.keySet()) {
                    log.trace("value for " + key + " is :" + map.get(key));
                }
            }
        } else {
            log.trace(when + "CacheManager is " + cacheManager);
        }
    }
}
 
Example 2
Source File: CacheDirectorImpl.java    From yes-cart with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void evictAllCache(final boolean force) {
    final CacheManager cm = getCacheManager();
    for (String cacheName : cm.getCacheNames()) {
        if (force || !this.skipEvictAll.contains(cacheName)) {
            final Cache cache = cm.getCache(cacheName);
            cache.clear();
        }
    }
}
 
Example 3
Source File: BaseCoreDBTestCase.java    From yes-cart with Apache License 2.0 5 votes vote down vote up
@After
public void tearDown() throws Exception {

    final CacheManager cacheManager = (CacheManager) ctx().getBean("cacheManager");
    for (final String name : cacheManager.getCacheNames()) {
        // clear all cache between the tests
        cacheManager.getCache(name).clear();
    }
}
 
Example 4
Source File: BaseCoreDBTestCase.java    From yes-cart with Apache License 2.0 5 votes vote down vote up
protected Map<String, Cache> getCacheMap() {
    final CacheManager cm = ctx().getBean("cacheManager", CacheManager.class);
    final Collection<String> cacheNames = cm.getCacheNames();
    final Map<String, Cache> cacheMap = new HashMap<>(cacheNames.size());
    for (String cacheName : cacheNames) {

        cacheMap.put(cacheName, cm.getCache(cacheName));

    }

    return cacheMap;
}
 
Example 5
Source File: CacheServiceImpl.java    From kfs with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * @see org.kuali.kfs.sys.batch.service.CacheService#clearSystemCache()
 */
@Override
public void clearSystemCaches() {
    for ( CacheManager cm :  CoreImplServiceLocator.getCacheManagerRegistry().getCacheManagers() ) {
        for ( String cacheName : cm.getCacheNames() ) {
            cm.getCache(cacheName).clear();
        }
    }
}
 
Example 6
Source File: KEWTestCase.java    From rice with Educational Community License v2.0 5 votes vote down vote up
protected void clearCacheManagers(CacheManager... cacheManagers) {
    for (CacheManager cacheManager : cacheManagers) {
        for (String cacheName : cacheManager.getCacheNames()) {
            LOG.info("Clearing cache: " + cacheName);
            cacheManager.getCache(cacheName).clear();
        }
    }
}
 
Example 7
Source File: CacheAdminController.java    From rice with Educational Community License v2.0 5 votes vote down vote up
@Override
@RequestMapping(params = "methodToCall=start")
public ModelAndView start(UifFormBase form) {

       final Tree<String, String> cacheTree = new Tree<String,String>();

       final Node<String,String> root = new Node<String,String>("Root", "Root");
       final List<CacheManager> cms = new ArrayList<CacheManager>(getRegistry().getCacheManagers());
       Collections.sort(cms, new ByName());

       for (final CacheManager cm : cms) {
           final String name = getRegistry().getCacheManagerName(cm);
           final Node<String, String> cmNode = new Node<String, String>(name, name);
           final List<String> names = new ArrayList<String>(cm.getCacheNames());
           Collections.sort(names, String.CASE_INSENSITIVE_ORDER);

           for (final String cn : names) {
               String cacheSize = getCacheSize(name, cn);
               final Node<String, String> cNode = new Node<String, String>(cn, cn + (cacheSize != null ? " - " + cacheSize : ""));
               //no way to get a keySet from the cache w/o calling the nativeCache
               //method which is a bad idea b/c it will tie the rice codebase to
               //a caching implementation
               cmNode.addChild(cNode);
           }

           root.addChild(cmNode);
       }

       cacheTree.setRootElement(root);
       ((CacheAdminForm) form).setCacheTree(cacheTree);

       return super.start(form);
   }
 
Example 8
Source File: CacheAdminController.java    From rice with Educational Community License v2.0 5 votes vote down vote up
private static void flushSpecificCache(CacheManager cm, String cache) {
    for (String s : cm.getCacheNames()) {
        if (cache.equals(s)) {
             cm.getCache(s).clear();
             return;
        }
    }
}
 
Example 9
Source File: CacheManagerRegistryImpl.java    From rice with Educational Community License v2.0 5 votes vote down vote up
public void setCacheManager(CacheManager c) {
    if (c == null) {
        throw new IllegalArgumentException("c is null");
    }

    CACHE_MANAGERS.add(c);

    //keep map as well
    for (String cacheName : c.getCacheNames()) {
        CACHE_MANAGER_MAP.put(cacheName, c);
    }
}
 
Example 10
Source File: CacheAdminController.java    From rice with Educational Community License v2.0 4 votes vote down vote up
private static void flushAllCaches(CacheManager cm) {
    for (String s : cm.getCacheNames()) {
        cm.getCache(s).clear();
    }
}