use of org.exoplatform.services.cache.invalidation.InvalidationExoCache in project kernel by exoplatform.
the class CacheServiceImpl method createCacheInstance.
@SuppressWarnings({ "rawtypes", "unchecked" })
private ExoCache<? extends Serializable, ?> createCacheInstance(String region) throws Exception {
ExoCacheConfig config = configs_.get(region);
if (config == null)
config = defaultConfig_;
// Ensure the configuration integrity
final ExoCacheConfig safeConfig = config.clone();
// Set the region as name
safeConfig.setName(region);
ExoCache simple = null;
if (// NOSONAR
factory_ != DEFAULT_FACTORY && safeConfig.getClass().isAssignableFrom(ExoCacheConfig.class) && safeConfig.getImplementation() != null) {
// we assume that we expect to use the default cache factory
try {
// We check if the given implementation is a known class
Class<?> implClass = ClassLoading.loadClass(safeConfig.getImplementation(), this);
// Implementation is an existing class
if (ExoCache.class.isAssignableFrom(implClass)) {
// The implementation is a sub class of eXo Cache so we use the default factory
simple = DEFAULT_FACTORY.createCache(safeConfig);
}
} catch (ClassNotFoundException e) {
if (LOG.isTraceEnabled()) {
LOG.trace("An exception occurred: " + e.getMessage());
}
}
}
if (simple == null) {
// We use the configured cache factory
simple = factory_.createCache(safeConfig);
}
if (managed != null) {
managed.registerCache(simple);
}
// to enable the invalidation
return safeConfig.avoidValueReplication() && (safeConfig.isRepicated() || safeConfig.isDistributed()) ? new InvalidationExoCache(simple) : simple;
}
Aggregations