Search in sources :

Example 96 with CacheManager

use of net.sf.ehcache.CacheManager in project BroadleafCommerce by BroadleafCommerce.

the class MergeEhCacheManagerFactoryBean method destroy.

@Override
public void destroy() {
    super.destroy();
    try {
        CacheManager cacheManager = getObject();
        Field cacheManagerTimer = CacheManager.class.getDeclaredField("cacheManagerTimer");
        cacheManagerTimer.setAccessible(true);
        Object failSafeTimer = cacheManagerTimer.get(cacheManager);
        Field timer = failSafeTimer.getClass().getDeclaredField("timer");
        timer.setAccessible(true);
        Object time = timer.get(failSafeTimer);
        Field thread = time.getClass().getDeclaredField("thread");
        thread.setAccessible(true);
        Thread item = (Thread) thread.get(time);
        item.setContextClassLoader(Thread.currentThread().getContextClassLoader().getParent());
    } catch (NoSuchFieldException e) {
        throw new RuntimeException(e);
    } catch (IllegalAccessException e) {
        throw new RuntimeException(e);
    }
}
Also used : Field(java.lang.reflect.Field) CacheManager(net.sf.ehcache.CacheManager)

Example 97 with CacheManager

use of net.sf.ehcache.CacheManager in project onebusaway-application-modules by camsys.

the class BundleManagementServiceImpl method removeAndRebuildCache.

/**
 ***********************
 * Private Helper Methods
 ************************
 */
private void removeAndRebuildCache() {
    // give subclasses a chance to do work
    timingHook();
    _log.info("Clearing all caches...");
    for (CacheManager cacheManager : CacheManager.ALL_CACHE_MANAGERS) {
        _log.info("Found " + cacheManager.getName());
        for (String cacheName : cacheManager.getCacheNames()) {
            _log.info(" > Cache: " + cacheName);
            cacheManager.getCache(cacheName).flush();
            cacheManager.clearAllStartingWith(cacheName);
        }
        // why not?
        cacheManager.clearAll();
    }
    // Rebuild cache
    try {
        List<AgencyWithCoverageBean> agenciesWithCoverage = _transitDataService.getAgenciesWithCoverage();
        for (AgencyWithCoverageBean agencyWithCoverage : agenciesWithCoverage) {
            AgencyBean agency = agencyWithCoverage.getAgency();
            ListBean<String> stopIds = _transitDataService.getStopIdsForAgencyId(agency.getId());
            for (String stopId : stopIds.getList()) {
                _transitDataService.getStop(stopId);
            }
            ListBean<String> routeIds = _transitDataService.getRouteIdsForAgencyId(agency.getId());
            for (String routeId : routeIds.getList()) {
                _transitDataService.getStopsForRoute(routeId);
            }
        }
        Set<AgencyAndId> shapeIds = new HashSet<AgencyAndId>();
        for (TripEntry trip : _transitGraphDao.getAllTrips()) {
            AgencyAndId shapeId = trip.getShapeId();
            if (shapeId != null && shapeId.hasValues())
                shapeIds.add(shapeId);
        }
        for (AgencyAndId shapeId : shapeIds) {
            _transitDataService.getShapeForId(AgencyAndIdLibrary.convertToString(shapeId));
        }
        _log.info("cache clearing complete!");
    } catch (Exception e) {
        _log.error("Exception during cache rebuild: ", e.getMessage());
    }
}
Also used : AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) AgencyWithCoverageBean(org.onebusaway.transit_data.model.AgencyWithCoverageBean) CacheManager(net.sf.ehcache.CacheManager) TripEntry(org.onebusaway.transit_data_federation.services.transit_graph.TripEntry) AgencyBean(org.onebusaway.transit_data.model.AgencyBean) HashSet(java.util.HashSet)

Example 98 with CacheManager

use of net.sf.ehcache.CacheManager in project gravitee-gateway by gravitee-io.

the class ApiKeysCacheConfiguration method cache.

@Bean
public Cache cache() {
    CacheManager cacheManager = cacheManager();
    Cache apiKeyCache = cacheManager.getCache(API_KEY_CACHE_NAME);
    if (apiKeyCache == null) {
        LOGGER.warn("EHCache cache for apikey not found. Fallback to default EHCache configuration");
        CacheConfiguration cacheConfiguration = new CacheConfiguration(API_KEY_CACHE_NAME, 1000);
        cacheManager.addCache(new Cache(cacheConfiguration));
    }
    return cacheManager.getCache(API_KEY_CACHE_NAME);
}
Also used : CacheManager(net.sf.ehcache.CacheManager) CacheConfiguration(net.sf.ehcache.config.CacheConfiguration) Cache(net.sf.ehcache.Cache) Bean(org.springframework.context.annotation.Bean)

Example 99 with CacheManager

use of net.sf.ehcache.CacheManager in project qi4j-sdk by Qi4j.

the class EhCachePoolMixin method activateCache.

@Override
public void activateCache() throws Exception {
    net.sf.ehcache.config.Configuration configuration = new net.sf.ehcache.config.Configuration();
    configureEhCache(configuration);
    CacheConfiguration cc = createCacheConfiguration("qi4j.ehcache.config.default");
    configuration.setDefaultCacheConfiguration(cc);
    cacheManager = new CacheManager(configuration);
}
Also used : PersistenceConfiguration(net.sf.ehcache.config.PersistenceConfiguration) CacheConfiguration(net.sf.ehcache.config.CacheConfiguration) Configuration(org.qi4j.api.configuration.Configuration) CacheManager(net.sf.ehcache.CacheManager) CacheConfiguration(net.sf.ehcache.config.CacheConfiguration)

Example 100 with CacheManager

use of net.sf.ehcache.CacheManager in project simplejpa by appoxy.

the class EhCacheFactory method init.

public synchronized void init(Map properties) {
    if (manager != null) {
        log.warning("Attempt to restart an already started CacheFactory. Using previously created EhCacheFactory.");
        return;
    }
    initializing = true;
    try {
        String configurationResourceName = null;
        if (properties != null) {
            configurationResourceName = (String) properties.get(NET_SF_EHCACHE_CONFIGURATION_RESOURCE_NAME);
        }
        if (configurationResourceName == null || configurationResourceName.length() == 0) {
            manager = new CacheManager();
        } else {
            if (!configurationResourceName.startsWith("/")) {
                configurationResourceName = "/" + configurationResourceName;
                if (log.isLoggable(Level.FINE)) {
                    log.fine("prepending / to " + configurationResourceName + ". It should be placed in the root" + "of the classpath rather than in a package.");
                }
            }
            URL url = loadResource(configurationResourceName);
            manager = new CacheManager(url);
        }
    } catch (net.sf.ehcache.CacheException e) {
        if (e.getMessage().startsWith("Cannot parseConfiguration CacheManager. Attempt to create a new instance of " + "CacheManager using the diskStorePath")) {
            throw new CacheException("Could not init EhCacheFactory.", e);
        } else {
            throw e;
        }
    } finally {
        initializing = false;
    }
}
Also used : CacheException(net.sf.ehcache.CacheException) CacheManager(net.sf.ehcache.CacheManager) URL(java.net.URL) CacheException(net.sf.ehcache.CacheException)

Aggregations

CacheManager (net.sf.ehcache.CacheManager)102 Cache (net.sf.ehcache.Cache)55 ClassPathResource (org.springframework.core.io.ClassPathResource)21 Element (net.sf.ehcache.Element)20 Configuration (net.sf.ehcache.config.Configuration)18 Test (org.junit.Test)18 CacheConfiguration (net.sf.ehcache.config.CacheConfiguration)17 MarkupCache (org.apache.wicket.markup.MarkupCache)10 CacheException (net.sf.ehcache.CacheException)9 IOException (java.io.IOException)7 Ehcache (net.sf.ehcache.Ehcache)7 UpdatingSelfPopulatingCache (net.sf.ehcache.constructs.blocking.UpdatingSelfPopulatingCache)6 URL (java.net.URL)5 BlockingCache (net.sf.ehcache.constructs.blocking.BlockingCache)5 SelfPopulatingCache (net.sf.ehcache.constructs.blocking.SelfPopulatingCache)5 DiskStoreConfiguration (net.sf.ehcache.config.DiskStoreConfiguration)4 PersistenceConfiguration (net.sf.ehcache.config.PersistenceConfiguration)4 Around (org.aspectj.lang.annotation.Around)4 Before (org.junit.Before)4 File (java.io.File)3