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);
}
}
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());
}
}
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);
}
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);
}
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;
}
}
Aggregations