use of net.sf.ehcache.Ehcache in project killbill by killbill.
the class AdminResource method invalidatesCacheByTenant.
@DELETE
@Path("/" + CACHE + "/" + TENANTS)
@Produces(APPLICATION_JSON)
@ApiOperation(value = "Invalidates Caches per tenant level")
@ApiResponses(value = {})
public Response invalidatesCacheByTenant(@QueryParam("tenantApiKey") final String tenantApiKey, @javax.ws.rs.core.Context final HttpServletRequest request) throws TenantApiException {
// creating Tenant Context from Request
TenantContext tenantContext = context.createContext(request);
Tenant currentTenant = tenantApi.getTenantById(tenantContext.getTenantId());
// getting Tenant Record Id
Long tenantRecordId = recordIdApi.getRecordId(tenantContext.getTenantId(), ObjectType.TENANT, tenantContext);
// clear tenant-record-id cache by tenantId
final Ehcache tenantRecordIdCache = cacheManager.getEhcache(CacheType.TENANT_RECORD_ID.getCacheName());
tenantRecordIdCache.remove(currentTenant.getId().toString());
// clear tenant-payment-state-machine-config cache by tenantRecordId
final Ehcache tenantPaymentStateMachineConfigCache = cacheManager.getEhcache(CacheType.TENANT_PAYMENT_STATE_MACHINE_CONFIG.getCacheName());
removeCacheByKey(tenantPaymentStateMachineConfigCache, tenantRecordId.toString());
// clear tenant cache by tenantApiKey
final Ehcache tenantCache = cacheManager.getEhcache(CacheType.TENANT.getCacheName());
tenantCache.remove(currentTenant.getApiKey());
// clear tenant-kv cache by tenantRecordId
final Ehcache tenantKvCache = cacheManager.getEhcache(CacheType.TENANT_KV.getCacheName());
removeCacheByKey(tenantKvCache, tenantRecordId.toString());
// clear tenant-config cache by tenantRecordId
final Ehcache tenantConfigCache = cacheManager.getEhcache(CacheType.TENANT_CONFIG.getCacheName());
tenantConfigCache.remove(tenantRecordId);
// clear tenant-overdue-config cache by tenantRecordId
final Ehcache tenantOverdueConfigCache = cacheManager.getEhcache(CacheType.TENANT_OVERDUE_CONFIG.getCacheName());
tenantOverdueConfigCache.remove(tenantRecordId);
// clear tenant-catalog cache by tenantRecordId
final Ehcache tenantCatalogCache = cacheManager.getEhcache(CacheType.TENANT_CATALOG.getCacheName());
tenantCatalogCache.remove(tenantRecordId);
return Response.status(Status.OK).build();
}
use of net.sf.ehcache.Ehcache in project killbill by killbill.
the class AdminResource method invalidatesCache.
@DELETE
@Path("/" + CACHE)
@Produces(APPLICATION_JSON)
@ApiOperation(value = "Invalidates the given Cache if specified, otherwise invalidates all caches")
@ApiResponses(value = { @ApiResponse(code = 400, message = "Cache name does not exist or is not alive") })
public Response invalidatesCache(@QueryParam("cacheName") final String cacheName, @javax.ws.rs.core.Context final HttpServletRequest request) {
if (null != cacheName && !cacheName.isEmpty()) {
final Ehcache cache = cacheManager.getEhcache(cacheName);
// check if cache is null
if (cache == null) {
log.warn("Cache for specified cacheName='{}' does not exist or is not alive", cacheName);
return Response.status(Status.BAD_REQUEST).build();
}
// Clear given cache
cache.removeAll();
} else {
// if not given a specific cacheName, clear all
cacheManager.clearAll();
}
return Response.status(Status.OK).build();
}
use of net.sf.ehcache.Ehcache in project ORCID-Source by ORCID.
the class OrcidEhCacheFactoryBean method afterPropertiesSet.
@Override
public void afterPropertiesSet() throws Exception {
Ehcache existingCache = cacheManager.getEhcache(cacheName);
String diskStorePath = cacheManager.getConfiguration().getDiskStoreConfiguration().getPath();
LOGGER.debug("Cache manager disk store path = " + diskStorePath);
if (existingCache == null) {
CacheConfiguration config = createConfig();
if (cacheEntryFactory != null) {
this.cache = new SelfPopulatingCache(new Cache(config), cacheEntryFactory);
} else {
this.cache = new Cache(config);
}
cacheManager.addCache(this.cache);
} else {
this.cache = existingCache;
}
}
use of net.sf.ehcache.Ehcache in project spring-framework by spring-projects.
the class EhCacheFactoryBean method afterPropertiesSet.
@Override
public void afterPropertiesSet() throws CacheException {
// If no cache name given, use bean name as cache name.
String cacheName = getName();
if (cacheName == null) {
cacheName = this.beanName;
setName(cacheName);
}
// If no CacheManager given, fetch the default.
if (this.cacheManager == null) {
if (logger.isDebugEnabled()) {
logger.debug("Using default EhCache CacheManager for cache region '" + cacheName + "'");
}
this.cacheManager = CacheManager.getInstance();
}
synchronized (this.cacheManager) {
// Fetch cache region: If none with the given name exists, create one on the fly.
Ehcache rawCache;
boolean cacheExists = this.cacheManager.cacheExists(cacheName);
if (cacheExists) {
if (logger.isDebugEnabled()) {
logger.debug("Using existing EhCache cache region '" + cacheName + "'");
}
rawCache = this.cacheManager.getEhcache(cacheName);
} else {
if (logger.isDebugEnabled()) {
logger.debug("Creating new EhCache cache region '" + cacheName + "'");
}
rawCache = createCache();
rawCache.setBootstrapCacheLoader(this.bootstrapCacheLoader);
}
if (this.cacheEventListeners != null) {
for (CacheEventListener listener : this.cacheEventListeners) {
rawCache.getCacheEventNotificationService().registerListener(listener);
}
}
// Needs to happen after listener registration but before setStatisticsEnabled
if (!cacheExists) {
this.cacheManager.addCache(rawCache);
}
if (this.disabled) {
rawCache.setDisabled(true);
}
Ehcache decoratedCache = decorateCache(rawCache);
if (decoratedCache != rawCache) {
this.cacheManager.replaceCacheWithDecoratedCache(rawCache, decoratedCache);
}
this.cache = decoratedCache;
}
}
use of net.sf.ehcache.Ehcache in project killbill by killbill.
the class TestCache method testInvalidateCacheByName.
@Test(groups = "slow", description = "Can Invalidate (clear) a Cache by name")
public void testInvalidateCacheByName() throws Exception {
// get Ehcache item with name "record-id"
final Ehcache cache = cacheManager.getEhcache(CacheType.RECORD_ID.getCacheName());
// verify that it is not null and has one stored key (the default tenant created for all integration tests)
assertNotNull(cache);
Assert.assertEquals(cache.getSize(), 1);
// invalidate the specified cache
killBillClient.invalidateCacheByName(cache.getName(), requestOptions);
// verify that now the cache is empty and has no keys stored
Assert.assertEquals(cache.getSize(), 0);
}
Aggregations