Example usage for org.springframework.cache.ehcache EhCacheManagerUtils parseConfiguration

List of usage examples for org.springframework.cache.ehcache EhCacheManagerUtils parseConfiguration

Introduction

In this page you can find the example usage for org.springframework.cache.ehcache EhCacheManagerUtils parseConfiguration.

Prototype

public static Configuration parseConfiguration(Resource configLocation) throws CacheException 

Source Link

Document

Parse EhCache configuration from the given resource, for further use with custom CacheManager creation.

Usage

From source file:org.springframework.cache.ehcache.EhCacheManagerFactoryBean.java

@Override
public void afterPropertiesSet() throws CacheException {
    if (logger.isInfoEnabled()) {
        logger.info("Initializing EhCache CacheManager"
                + (this.cacheManagerName != null ? " '" + this.cacheManagerName + "'" : ""));
    }/*w ww.  ja v a2s  .c o  m*/

    Configuration configuration = (this.configLocation != null
            ? EhCacheManagerUtils.parseConfiguration(this.configLocation)
            : ConfigurationFactory.parseConfiguration());
    if (this.cacheManagerName != null) {
        configuration.setName(this.cacheManagerName);
    }

    if (this.shared) {
        // Old-school EhCache singleton sharing...
        // No way to find out whether we actually created a new CacheManager
        // or just received an existing singleton reference.
        this.cacheManager = CacheManager.create(configuration);
    } else if (this.acceptExisting) {
        // EhCache 2.5+: Reusing an existing CacheManager of the same name.
        // Basically the same code as in CacheManager.getInstance(String),
        // just storing whether we're dealing with an existing instance.
        synchronized (CacheManager.class) {
            this.cacheManager = CacheManager.getCacheManager(this.cacheManagerName);
            if (this.cacheManager == null) {
                this.cacheManager = new CacheManager(configuration);
            } else {
                this.locallyManaged = false;
            }
        }
    } else {
        // Throwing an exception if a CacheManager of the same name exists already...
        this.cacheManager = new CacheManager(configuration);
    }
}