use of net.sf.ehcache.Ehcache in project hibernate-orm by hibernate.
the class AbstractEhcacheRegionFactory method getCache.
private Ehcache getCache(String name) throws CacheException {
try {
Ehcache cache = manager.getEhcache(name);
if (cache == null) {
LOG.unableToFindEhCacheConfiguration(name);
manager.addCache(name);
cache = manager.getEhcache(name);
LOG.debug("started EHCache region: " + name);
}
return cache;
} catch (net.sf.ehcache.CacheException e) {
throw new CacheException(e);
}
}
use of net.sf.ehcache.Ehcache in project killbill by killbill.
the class TestCache method testInvalidateCacheByTenant.
@Test(groups = "slow", description = "Can Invalidate (clear) all Tenant Caches for current Tenant")
public void testInvalidateCacheByTenant() throws Exception {
// creating a new Tenant for this test
final String testApiKey = "testApiKey";
final String testApiSecret = "testApiSecret";
final Tenant tenant = new Tenant();
tenant.setApiKey(testApiKey);
tenant.setApiSecret(testApiSecret);
loginTenant(testApiKey, testApiSecret);
Tenant currentTenant = killBillClient.createTenant(tenant, false, requestOptions);
// using custom RequestOptions with the new Tenant created before
RequestOptions inputOptions = RequestOptions.builder().withCreatedBy(createdBy).withReason(reason).withComment(comment).withTenantApiKey(currentTenant.getApiKey()).withTenantApiSecret(currentTenant.getApiSecret()).build();
// Uploading the test catalog using the new Tenant created before
killBillClient.uploadXMLCatalog(Resources.getResource("SpyCarAdvanced.xml").getPath(), inputOptions);
// creating an Account with PaymentMethod and a Subscription
createAccountWithPMBundleAndSubscriptionAndWaitForFirstInvoiceWithInputOptions(inputOptions);
// get all caches per tenant level
final Ehcache tenantRecordIdCache = cacheManager.getEhcache(CacheType.TENANT_RECORD_ID.getCacheName());
final Ehcache tenantPaymentStateMachineConfigCache = cacheManager.getEhcache(CacheType.TENANT_PAYMENT_STATE_MACHINE_CONFIG.getCacheName());
final Ehcache tenantCache = cacheManager.getEhcache(CacheType.TENANT.getCacheName());
final Ehcache tenantKvCache = cacheManager.getEhcache(CacheType.TENANT_KV.getCacheName());
final Ehcache tenantConfigCache = cacheManager.getEhcache(CacheType.TENANT_CONFIG.getCacheName());
final Ehcache tenantOverdueConfigCache = cacheManager.getEhcache(CacheType.TENANT_OVERDUE_CONFIG.getCacheName());
final Ehcache tenantCatalogCache = cacheManager.getEhcache(CacheType.TENANT_CATALOG.getCacheName());
// getting current Tenant's record Id from the specific Cache
Long tenantRecordId = (Long) tenantRecordIdCache.get(currentTenant.getTenantId().toString()).getObjectValue();
// verify that they are not null and have the expected tenant information
assertNotNull(tenantRecordIdCache);
assertNotNull(tenantRecordIdCache.get(currentTenant.getTenantId().toString()));
assertNotNull(tenantPaymentStateMachineConfigCache);
assertTrue(hasKeysByTenantRecordId(tenantPaymentStateMachineConfigCache, tenantRecordId.toString()));
assertNotNull(tenantCache);
assertNotNull(tenantCache.get(testApiKey));
assertNotNull(tenantKvCache);
assertTrue(hasKeysByTenantRecordId(tenantKvCache, tenantRecordId.toString()));
assertNotNull(tenantConfigCache);
assertNotNull(tenantConfigCache.get(tenantRecordId));
assertNotNull(tenantOverdueConfigCache);
assertNotNull(tenantOverdueConfigCache.get(tenantRecordId));
assertNotNull(tenantCatalogCache);
assertNotNull(tenantCatalogCache.get(tenantRecordId));
// invalidate caches per tenant level
killBillClient.invalidateCacheByTenant(inputOptions);
// verify that now the caches don't have the previous values
Assert.assertNull(tenantRecordIdCache.get(currentTenant.getTenantId().toString()));
assertFalse(hasKeysByTenantRecordId(tenantPaymentStateMachineConfigCache, tenantRecordId.toString()));
Assert.assertNull(tenantCache.get(testApiKey));
assertFalse(hasKeysByTenantRecordId(tenantKvCache, tenantRecordId.toString()));
Assert.assertNull(tenantConfigCache.get(tenantRecordId));
Assert.assertNull(tenantOverdueConfigCache.get(tenantRecordId));
Assert.assertNull(tenantCatalogCache.get(tenantRecordId));
}
use of net.sf.ehcache.Ehcache in project killbill by killbill.
the class ShiroEhCacheInstrumentor method instrument.
public void instrument(final String cacheName) {
// Initialize the cache, if it doesn't exist yet
// Note: Shiro's cache manager is not thread safe. Concurrent requests on startup
// can throw org.apache.shiro.cache.CacheException: net.sf.ehcache.ObjectExistsException: Cache shiro-activeSessionCache already exists
shiroEhCacheManager.getCache(cacheName);
final Ehcache shiroEhcache = ehCacheCacheManager.getEhcache(cacheName);
final Ehcache decoratedCache = InstrumentedEhcache.instrument(metricRegistry, shiroEhcache);
try {
ehCacheCacheManager.replaceCacheWithDecoratedCache(shiroEhcache, decoratedCache);
} catch (final CacheException e) {
logger.warn("Unable to instrument cache {}: {}", shiroEhcache.getName(), e.getMessage());
}
}
use of net.sf.ehcache.Ehcache in project killbill by killbill.
the class AdminResource method invalidatesCacheByAccount.
@DELETE
@Path("/" + CACHE + "/" + ACCOUNTS + "/{accountId:" + UUID_PATTERN + "}/")
@Produces(APPLICATION_JSON)
@ApiOperation(value = "Invalidates Caches per account level")
@ApiResponses(value = {})
public Response invalidatesCacheByAccount(@PathParam("accountId") final String accountId, @javax.ws.rs.core.Context final HttpServletRequest request) {
// clear account-record-id cache by accountId
final Ehcache accountRecordIdCache = cacheManager.getEhcache(CacheType.ACCOUNT_RECORD_ID.getCacheName());
accountRecordIdCache.remove(accountId);
// clear account-immutable cache by accountId
final Ehcache accountImmutableCache = cacheManager.getEhcache(CacheType.ACCOUNT_IMMUTABLE.getCacheName());
accountImmutableCache.remove(UUID.fromString(accountId));
// clear account-bcd cache by accountId
final Ehcache accountBcdCache = cacheManager.getEhcache(CacheType.ACCOUNT_BCD.getCacheName());
accountBcdCache.remove(UUID.fromString(accountId));
return Response.status(Status.OK).build();
}
use of net.sf.ehcache.Ehcache in project camel by apache.
the class CacheBasedTokenReplacer method process.
public void process(Exchange exchange) throws Exception {
String cacheKey = key.evaluate(exchange, String.class);
if (isValid(cacheManager, cacheName, cacheKey)) {
Ehcache cache = cacheManager.getCache(cacheName);
if (LOG.isDebugEnabled()) {
LOG.debug("Replacing Token {} in Message with value stored against key {} in CacheName {}", new Object[] { replacementToken, cacheKey, cacheName });
}
exchange.getIn().setHeader(CacheConstants.CACHE_KEY, cacheKey);
Object body = exchange.getIn().getBody();
InputStream is = exchange.getContext().getTypeConverter().convertTo(InputStream.class, body);
byte[] buffer;
try {
buffer = IOConverter.toBytes(is);
} finally {
IOHelper.close(is, "is", LOG);
}
// Note: The value in the cache must be a String
String cacheValue = exchange.getContext().getTypeConverter().convertTo(String.class, cache.get(cacheKey).getObjectValue());
String replacedTokenString = new String(buffer).replaceAll(replacementToken, cacheValue);
LOG.trace("replacedTokenString = {}", replacedTokenString);
exchange.getIn().setBody(replacedTokenString.getBytes());
}
}
Aggregations