Search in sources :

Example 51 with CacheConfiguration

use of net.sf.ehcache.config.CacheConfiguration in project openmrs-core by openmrs.

the class CachePropertiesUtil method addCacheConfigsFormResourceToList.

private static void addCacheConfigsFormResourceToList(Resource resource, List<CacheConfiguration> openmrsCacheConfigurationList) {
    Properties cacheProperties = getPropertiesFromResource(resource);
    getAllCacheNames(cacheProperties.keySet()).forEach(cacheName -> {
        OpenmrsCacheConfiguration openmrsCacheConfiguration = new OpenmrsCacheConfiguration();
        openmrsCacheConfiguration.addProperty("name", cacheName);
        cacheProperties.keySet().stream().filter(key -> key.toString().startsWith(cacheName)).forEach(key -> {
            String s = key.toString();
            openmrsCacheConfiguration.addProperty(s.replace(cacheName + ".", ""), cacheProperties.getProperty(key.toString()));
        });
        openmrsCacheConfigurationList.add(createCacheConfiguration(openmrsCacheConfiguration));
    });
}
Also used : Arrays(java.util.Arrays) CacheConfiguration(net.sf.ehcache.config.CacheConfiguration) Properties(java.util.Properties) BeanUtils(org.apache.commons.beanutils.BeanUtils) Set(java.util.Set) IOException(java.io.IOException) InvocationTargetException(java.lang.reflect.InvocationTargetException) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) PathMatchingResourcePatternResolver(org.springframework.core.io.support.PathMatchingResourcePatternResolver) List(java.util.List) ResourcePatternResolver(org.springframework.core.io.support.ResourcePatternResolver) InputStream(java.io.InputStream) Resource(org.springframework.core.io.Resource) Properties(java.util.Properties)

Example 52 with CacheConfiguration

use of net.sf.ehcache.config.CacheConfiguration in project openmrs-core by openmrs.

the class OpenmrsCacheManagerFactoryBean method getObject.

@Override
public CacheManager getObject() {
    CacheManager cacheManager = super.getObject();
    Map<String, CacheConfiguration> cacheConfig = cacheManager.getConfiguration().getCacheConfigurations();
    List<CacheConfiguration> cacheConfigurations = CachePropertiesUtil.getCacheConfigurations();
    cacheConfigurations.stream().filter(cc -> cacheConfig.get(cc.getName()) == null).forEach(cc -> cacheManager.addCache(new Cache(cc)));
    return cacheManager;
}
Also used : List(java.util.List) CacheConfiguration(net.sf.ehcache.config.CacheConfiguration) EhCacheManagerFactoryBean(org.springframework.cache.ehcache.EhCacheManagerFactoryBean) Map(java.util.Map) CacheManager(net.sf.ehcache.CacheManager) Cache(net.sf.ehcache.Cache) CacheManager(net.sf.ehcache.CacheManager) CacheConfiguration(net.sf.ehcache.config.CacheConfiguration) Cache(net.sf.ehcache.Cache)

Example 53 with CacheConfiguration

use of net.sf.ehcache.config.CacheConfiguration in project ff4j by ff4j.

the class FeatureStoreTerracottaTestIT method initStore.

/**
 * {@inheritDoc}
 */
@Override
protected FeatureStore initStore() {
    // Configuration to wirk with Terracotta
    Configuration managerConfiguration = new Configuration();
    managerConfiguration.name("config").terracotta(new TerracottaClientConfiguration().url(TERRACOTTA_URL)).defaultCache(new CacheConfiguration().maxBytesLocalHeap(128, MemoryUnit.MEGABYTES).terracotta(new TerracottaConfiguration())).cache(new CacheConfiguration().name(FF4jEhCacheWrapper.CACHENAME_FEATURES).maxBytesLocalHeap(128, MemoryUnit.MEGABYTES).terracotta(new TerracottaConfiguration()));
    FeatureStoreEhCache ehcacheStore = new FeatureStoreEhCache(managerConfiguration);
    ehcacheStore.importFeaturesFromXmlFile("ff4j.xml");
    return ehcacheStore;
}
Also used : TerracottaClientConfiguration(net.sf.ehcache.config.TerracottaClientConfiguration) CacheConfiguration(net.sf.ehcache.config.CacheConfiguration) TerracottaConfiguration(net.sf.ehcache.config.TerracottaConfiguration) Configuration(net.sf.ehcache.config.Configuration) TerracottaClientConfiguration(net.sf.ehcache.config.TerracottaClientConfiguration) TerracottaConfiguration(net.sf.ehcache.config.TerracottaConfiguration) FeatureStoreEhCache(org.ff4j.store.FeatureStoreEhCache) CacheConfiguration(net.sf.ehcache.config.CacheConfiguration)

Example 54 with CacheConfiguration

use of net.sf.ehcache.config.CacheConfiguration in project mica2 by obiba.

the class DatasetCacheResolver method resolveCaches.

@Override
public synchronized 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();
            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;
}
Also used : Arrays(java.util.Arrays) CacheConfiguration(net.sf.ehcache.config.CacheConfiguration) MetricRegistry(com.codahale.metrics.MetricRegistry) InstrumentedEhcache(com.codahale.metrics.ehcache.InstrumentedEhcache) Cache(org.springframework.cache.Cache) CacheOperationInvocationContext(org.springframework.cache.interceptor.CacheOperationInvocationContext) Collection(java.util.Collection) Dataset(org.obiba.mica.dataset.domain.Dataset) CacheResolver(org.springframework.cache.interceptor.CacheResolver) Inject(javax.inject.Inject) Component(org.springframework.stereotype.Component) Lists(com.google.common.collect.Lists) CacheManager(org.springframework.cache.CacheManager) EhCacheCache(org.springframework.cache.ehcache.EhCacheCache) Optional(java.util.Optional) Dataset(org.obiba.mica.dataset.domain.Dataset) EhCacheCache(org.springframework.cache.ehcache.EhCacheCache) CacheConfiguration(net.sf.ehcache.config.CacheConfiguration) Cache(org.springframework.cache.Cache) EhCacheCache(org.springframework.cache.ehcache.EhCacheCache)

Example 55 with CacheConfiguration

use of net.sf.ehcache.config.CacheConfiguration in project dble by actiontech.

the class EnchachePooFactory method createCachePool.

@Override
public CachePool createCachePool(String poolName, int cacheSize, int expiredSeconds) {
    CacheManager cacheManager = CacheManager.create();
    Cache enCache = cacheManager.getCache(poolName);
    if (enCache == null) {
        CacheConfiguration cacheConf = cacheManager.getConfiguration().getDefaultCacheConfiguration().clone();
        cacheConf.setName(poolName);
        if (cacheConf.getMaxEntriesLocalHeap() != 0) {
            cacheConf.setMaxEntriesLocalHeap(cacheSize);
        } else {
            cacheConf.setMaxBytesLocalHeap(String.valueOf(cacheSize));
        }
        cacheConf.setTimeToIdleSeconds(expiredSeconds);
        Cache cache = new Cache(cacheConf);
        cacheManager.addCache(cache);
        return new EnchachePool(poolName, cache, cacheSize);
    } else {
        return new EnchachePool(poolName, enCache, cacheSize);
    }
}
Also used : CacheManager(net.sf.ehcache.CacheManager) CacheConfiguration(net.sf.ehcache.config.CacheConfiguration) Cache(net.sf.ehcache.Cache)

Aggregations

CacheConfiguration (net.sf.ehcache.config.CacheConfiguration)71 Cache (net.sf.ehcache.Cache)26 CacheManager (net.sf.ehcache.CacheManager)16 Ehcache (net.sf.ehcache.Ehcache)14 Configuration (net.sf.ehcache.config.Configuration)14 Element (net.sf.ehcache.Element)9 PersistenceConfiguration (net.sf.ehcache.config.PersistenceConfiguration)8 DiskStoreConfiguration (net.sf.ehcache.config.DiskStoreConfiguration)6 Test (org.junit.Test)6 Resource (org.springframework.core.io.Resource)6 IOException (java.io.IOException)5 Bean (org.springframework.context.annotation.Bean)5 CachedResource (org.apereo.portal.utils.cache.resource.CachedResource)4 CachingResourceLoaderImpl (org.apereo.portal.utils.cache.resource.CachingResourceLoaderImpl)4 LoadedResource (org.apereo.portal.utils.cache.resource.LoadedResource)4 ResourcesElementsProvider (org.jasig.resourceserver.utils.aggr.ResourcesElementsProvider)4 FileSystemResource (org.springframework.core.io.FileSystemResource)4 FileReader (java.io.FileReader)3 URL (java.net.URL)3 SelfPopulatingCache (net.sf.ehcache.constructs.blocking.SelfPopulatingCache)3