Example usage for org.springframework.cache.ehcache EhCacheCache EhCacheCache

List of usage examples for org.springframework.cache.ehcache EhCacheCache EhCacheCache

Introduction

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

Prototype

public EhCacheCache(Ehcache ehcache) 

Source Link

Document

Create an EhCacheCache instance.

Usage

From source file:com.hp.autonomy.frontend.find.core.configuration.AutoCreatingEhCacheCacheManager.java

@Override
protected Cache getMissingCache(final String name) {
    final Cache missingCache = super.getMissingCache(name);

    if (missingCache == null) {
        final CacheConfiguration cacheConfiguration = defaults.clone().name(name);

        final String cacheName = getCacheName(name);

        if (FindCacheNames.CACHE_EXPIRES.containsKey(cacheName)) {
            cacheConfiguration.setTimeToLiveSeconds(FindCacheNames.CACHE_EXPIRES.get(cacheName));
        }/* ww w  . j  av  a 2 s.  c  om*/

        final net.sf.ehcache.Cache ehcache = new net.sf.ehcache.Cache(cacheConfiguration);
        ehcache.initialise();

        return new EhCacheCache(ehcache);
    } else {
        return missingCache;
    }
}

From source file:org.obiba.mica.dataset.DatasetCacheResolver.java

@Override
public Collection<? extends Cache> resolveCaches(
        CacheOperationInvocationContext<?> cacheOperationInvocationContext) {
    Collection<Cache> res = Lists.newArrayList();

    Optional<Object> dataset = Arrays.stream(cacheOperationInvocationContext.getArgs())
            .filter(o -> o instanceof Dataset).findFirst();

    if (dataset.isPresent()) {
        String cacheName = "dataset-" + ((Dataset) dataset.get()).getId();
        Cache datasetCache = springCacheManager.getCache(cacheName);

        if (datasetCache == null) {
            CacheConfiguration conf = cacheManager.getEhcache("dataset-variables").getCacheConfiguration()
                    .clone();//from  w  ww  . ja  v a 2  s . c  om
            conf.setName(cacheName);
            cacheManager.addCache(new net.sf.ehcache.Cache(conf));
            net.sf.ehcache.Cache cache = cacheManager.getCache(cacheName);
            cacheManager.replaceCacheWithDecoratedCache(cache,
                    InstrumentedEhcache.instrument(metricRegistry, cache));
            datasetCache = new EhCacheCache(cacheManager.getEhcache(cacheName));
        }

        res.add(datasetCache);
    }

    return res;
}