本文整理匯總了Java中net.sf.ehcache.CacheException類的典型用法代碼示例。如果您正苦於以下問題:Java CacheException類的具體用法?Java CacheException怎麽用?Java CacheException使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
CacheException類屬於net.sf.ehcache包,在下文中一共展示了CacheException類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: values
import net.sf.ehcache.CacheException; //導入依賴的package包/類
/**
* 獲取name下所有緩存值
*/
public <E> List<E> values(String name) {
try {
Set<String> elements = this.getElements(name);
if (null != elements && !elements.isEmpty()) {
List<String> keys = Lists.newArrayList();
for (String field : elements) {
keys.add(this.getRedisKeyOfElement(name, field));
}
return this.jedisTemplate.mget(keys);
} else {
return Collections.emptyList();
}
} catch (Throwable t) {
throw new CacheException(t);
}
}
示例2: getSystemPropertyValue
import net.sf.ehcache.CacheException; //導入依賴的package包/類
/**
* @return system property by name or default value if not
* found.
*/
public String getSystemPropertyValue(final String propertyName, final String defaultValue) {
try {
final Cache cache = getSystemPropertyCache();
final Element element = cache.get(propertyName);
if (element == null) {
final String value = getSystemPropertyValueFromDB(propertyName, defaultValue);
cache.put(new Element(propertyName, value));
return value;
} else {
return (String) element.getValue();
}
} catch (final CacheException ignored) {
return getSystemPropertyValueFromDB(propertyName, defaultValue);
}
}
示例3: limpiarCache
import net.sf.ehcache.CacheException; //導入依賴的package包/類
public static void limpiarCache(String idDominio) throws CacheException{
log.debug("Queremos borrarCache: " + idDominio);
String cacheName = PluginDominio.class.getName();
CacheManager cacheManager = CacheManager.getInstance();
Cache cache;
if (cacheManager.cacheExists(cacheName)) {
cache = cacheManager.getCache(cacheName);
List keys = cache.getKeys();
log.debug("Queremos borrarCache: " + idDominio + " que tiene " + keys.size() + " elementos.");
for (Iterator it=keys.iterator();it.hasNext();){
String key = (String) it.next();
int idx = key.indexOf(SEPARATOR);
if(idx != -1) cache.remove(key);
}
}
}
示例4: limpiarCache
import net.sf.ehcache.CacheException; //導入依賴的package包/類
public static void limpiarCache(String idDominio) throws CacheException{
log.debug("Queremos borrarCache: " + idDominio);
String cacheName = PluginAudita.class.getName();
CacheManager cacheManager = CacheManager.getInstance();
Cache cache;
if (cacheManager.cacheExists(cacheName)) {
cache = cacheManager.getCache(cacheName);
List keys = cache.getKeys();
log.debug("Queremos borrarCache: " + idDominio + " que tiene " + keys.size() + " elementos.");
for (Iterator it=keys.iterator();it.hasNext();){
String key = (String) it.next();
int idx = key.indexOf(SEPARATOR);
if(idx != -1) cache.remove(key);
}
}
}
示例5: testCacheManagerConflict
import net.sf.ehcache.CacheException; //導入依賴的package包/類
@Test
public void testCacheManagerConflict() throws Exception {
EhCacheManagerFactoryBean cacheManagerFb = new EhCacheManagerFactoryBean();
cacheManagerFb.setCacheManagerName("myCacheManager");
assertEquals(CacheManager.class, cacheManagerFb.getObjectType());
assertTrue("Singleton property", cacheManagerFb.isSingleton());
cacheManagerFb.afterPropertiesSet();
try {
CacheManager cm = cacheManagerFb.getObject();
assertTrue("Loaded CacheManager with no caches", cm.getCacheNames().length == 0);
Cache myCache1 = cm.getCache("myCache1");
assertTrue("No myCache1 defined", myCache1 == null);
EhCacheManagerFactoryBean cacheManagerFb2 = new EhCacheManagerFactoryBean();
cacheManagerFb2.setCacheManagerName("myCacheManager");
cacheManagerFb2.afterPropertiesSet();
fail("Should have thrown CacheException because of naming conflict");
}
catch (CacheException ex) {
// expected
}
finally {
cacheManagerFb.destroy();
}
}
示例6: getCacheAddress
import net.sf.ehcache.CacheException; //導入依賴的package包/類
private Object getCacheAddress(String cacheKey) {
Object cacheObject = null;
try {
myLog.debug("Try to get Cache Object for the key:" + cacheKey);
Cache cache = cacheManager.getCache(CACHE_NAME);
if (cache != null && cache.isElementInMemory(cacheKey) && cache.get(cacheKey) != null) {
cacheObject = cache.get(cacheKey).getObjectValue();
} else {
myLog.debug("Cache Object, key:" + cacheKey + " not found");
}
} catch (CacheException ex) {
myLog.error("Failed to get cached address: " + cacheKey, ex);
}
return cacheObject;
}
示例7: load
import net.sf.ehcache.CacheException; //導入依賴的package包/類
/**
* Loads the object with the provided key into the cache (called for instance
* by getWithLoader if element not found in the cache.
*
* <p>If this loader is in preloading mode (as indicated by the <code>preload</code>
* field, then this method looks for the object in the preload Map. If not
* in preload mode, it will look for the object in the database directly. If
* it is found in either of these, it will be loaded into the cache and
* returned. If not found in either, nothing is added to the cache and null
* is returned.
*
* <p>Notice that the returned null is never returned by a direct query to a
* {@link C2monCache}, in which case a {@link CacheElementNotFoundException} is
* thrown.
*/
@Override
public Object load(Object key) throws CacheException {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Fetching cache object with Id " + key + " from database.");
}
Object result = fetchFromDB(key);
//put in cache if found something
if (result != null) {
cache.putQuiet(new Element(key, result));
}
return result;
}
示例8: internalCreateCacheManager
import net.sf.ehcache.CacheException; //導入依賴的package包/類
/**
* Actual creation of the singleton.
*
* @param config
* the parsed EhCache configuration
* @return the cache manager
* @throws CacheException
* in case the creation failed
*/
private static synchronized CacheManager internalCreateCacheManager(Configuration config)
throws CacheException {
if (SINGLETON != null) {
extendEhCacheWithCustomConfig(SINGLETON, config);
} else {
// for better control over the files created by the application override the diskstore
// path
// for flushing cached data to disk
overrideDiskStorePath(config);
// disable the update check
config.setUpdateCheck(false);
SINGLETON = new CacheManager(config);
}
return SINGLETON;
}
示例9: process
import net.sf.ehcache.CacheException; //導入依賴的package包/類
public void process(Exchange exchange) throws Exception {
LOG.trace("Cache Name: {}", config.getCacheName());
Map<String, Object> headers = exchange.getIn().getHeaders();
String key = (headers.containsKey(CacheConstants.CACHE_KEY))
? exchange.getIn().getHeader(CacheConstants.CACHE_KEY, String.class)
: getEndpoint().getKey();
String operation = (headers.containsKey(CacheConstants.CACHE_OPERATION)) ? (String)headers
.get(CacheConstants.CACHE_OPERATION) : getEndpoint().getOperation();
if (operation == null) {
throw new CacheException(CacheConstants.CACHE_OPERATION + " header not specified in message");
}
if ((key == null) && (!checkIsEqual(operation, CacheConstants.CACHE_OPERATION_DELETEALL))) {
throw new CacheException(CacheConstants.CACHE_KEY + " is not specified in message header or endpoint URL.");
}
performCacheOperation(exchange, operation, key);
//cleanup the cache headers
exchange.getIn().removeHeader(CacheConstants.CACHE_KEY);
exchange.getIn().removeHeader(CacheConstants.CACHE_OPERATION);
}
示例10: dispatchExchange
import net.sf.ehcache.CacheException; //導入依賴的package包/類
private void dispatchExchange(Ehcache cache, Element element, String operation) {
Exchange exchange;
LOG.debug("Consumer Dispatching the Exchange containing the Element {} in cache {}", element, cache.getName());
if (element == null) {
exchange = cacheConsumer.getEndpoint().createCacheExchange(operation, "", "");
} else {
exchange = cacheConsumer.getEndpoint().createCacheExchange(operation, (String) element.getObjectKey(), element.getObjectValue());
}
try {
cacheConsumer.getProcessor().process(exchange);
} catch (Exception e) {
throw new CacheException("Error in consumer while dispatching exchange containing key "
+ (element != null ? element.getObjectKey() : null) + " for further processing", e);
}
}
示例11: testAddingDataToCacheDoesFailOnEmptyBody
import net.sf.ehcache.CacheException; //導入依賴的package包/類
@Test
public void testAddingDataToCacheDoesFailOnEmptyBody() throws Exception {
context.addRoutes(new RouteBuilder() {
public void configure() {
onException(CacheException.class).
handled(true).
to("log:LOGGER").
to("mock:CacheProducerTest.cacheException");
from("direct:a").
setHeader(CacheConstants.CACHE_OPERATION, constant(CacheConstants.CACHE_OPERATION_ADD)).
setHeader(CacheConstants.CACHE_KEY, constant("Ralph_Waldo_Emerson")).
to("cache://TestCache1");
}
});
resultEndpoint.expectedMessageCount(0);
cacheExceptionEndpoint.expectedMessageCount(1);
context.start();
log.debug("------------Beginning CacheProducer Add Does Fail On Empty Body Test---------------");
sendEmptyBody();
resultEndpoint.assertIsSatisfied();
cacheExceptionEndpoint.assertIsSatisfied();
}
示例12: testUpdatingDataInCacheDoesFailOnEmptyBody
import net.sf.ehcache.CacheException; //導入依賴的package包/類
@Test
public void testUpdatingDataInCacheDoesFailOnEmptyBody() throws Exception {
context.addRoutes(new RouteBuilder() {
public void configure() {
onException(CacheException.class).
handled(true).
to("log:LOGGER").
to("mock:CacheProducerTest.cacheException");
from("direct:a").
setHeader(CacheConstants.CACHE_OPERATION, constant(CacheConstants.CACHE_OPERATION_UPDATE)).
setHeader(CacheConstants.CACHE_KEY, constant("Ralph_Waldo_Emerson")).
to("cache://TestCache1");
}
});
cacheExceptionEndpoint.expectedMessageCount(1);
context.start();
log.debug("------------Beginning CacheProducer Update Does Fail On Empty Body Test---------------");
sendEmptyBody();
cacheExceptionEndpoint.assertIsSatisfied();
}
示例13: testDeletingDataFromCacheDoesNotFailOnEmptyBody
import net.sf.ehcache.CacheException; //導入依賴的package包/類
@Test
public void testDeletingDataFromCacheDoesNotFailOnEmptyBody() throws Exception {
context.addRoutes(new RouteBuilder() {
public void configure() {
onException(CacheException.class).
handled(true).
to("log:LOGGER").
to("mock:CacheProducerTest.cacheException");
from("direct:a").
setHeader(CacheConstants.CACHE_OPERATION, constant(CacheConstants.CACHE_OPERATION_DELETE)).
setHeader(CacheConstants.CACHE_KEY, constant("Ralph_Waldo_Emerson")).
to("cache://TestCache1");
}
});
cacheExceptionEndpoint.expectedMessageCount(0);
context.start();
log.debug("------------Beginning CacheProducer Delete Does Not Fail On Empty Body Test---------------");
sendEmptyBody();
cacheExceptionEndpoint.assertIsSatisfied();
}
示例14: testDeletingAllDataFromCacheDoesNotFailOnEmptyBody
import net.sf.ehcache.CacheException; //導入依賴的package包/類
@Test
public void testDeletingAllDataFromCacheDoesNotFailOnEmptyBody() throws Exception {
context.addRoutes(new RouteBuilder() {
public void configure() {
onException(CacheException.class).
handled(true).
to("log:LOGGER").
to("mock:CacheProducerTest.cacheException");
from("direct:a").
setHeader(CacheConstants.CACHE_OPERATION, constant(CacheConstants.CACHE_OPERATION_DELETEALL)).
to("cache://TestCache1");
}
});
cacheExceptionEndpoint.expectedMessageCount(0);
context.start();
log.debug("------------Beginning CacheProducer Delete All Elements Does Not Fail On Empty Body Test---------------");
sendEmptyBody();
cacheExceptionEndpoint.assertIsSatisfied();
}
示例15: testUnknownOperation
import net.sf.ehcache.CacheException; //導入依賴的package包/類
@Test
public void testUnknownOperation() throws Exception {
context.addRoutes(new RouteBuilder() {
public void configure() {
onException(CacheException.class).
handled(true).
to("log:LOGGER").
to("mock:CacheProducerTest.cacheException");
from("direct:a").
setHeader(CacheConstants.CACHE_OPERATION, constant("UNKNOWN")).
setHeader(CacheConstants.CACHE_KEY, constant("Ralph_Waldo_Emerson")).
to("cache://TestCache1").
to("mock:CacheProducerTest.result");
}
});
resultEndpoint.expectedMessageCount(0);
cacheExceptionEndpoint.expectedMessageCount(1);
context.start();
log.debug("------------Beginning CacheProducer Query An Elements Test---------------");
sendUpdatedFile();
resultEndpoint.assertIsSatisfied();
cacheExceptionEndpoint.assertIsSatisfied();
}