use of com.evolveum.midpoint.util.caching.CacheConfiguration.StatisticsLevel in project midpoint by Evolveum.
the class AbstractSearchExpressionEvaluator method executeSearchUsingCache.
private <O extends ObjectType> List<V> executeSearchUsingCache(Class<O> targetTypeClass, final QName targetTypeQName, ObjectQuery query, List<ItemDelta<V, D>> additionalAttributeDeltas, final ExpressionEvaluationContext params, String contextDescription, Task task, OperationResult result) throws ExpressionEvaluationException, ObjectNotFoundException, SchemaException {
CachePerformanceCollector collector = CachePerformanceCollector.INSTANCE;
Class<?> cacheClass = getCacheClass();
CacheType cacheType = getCacheType();
CacheConfiguration cacheConfiguration = cacheType != null ? cacheConfigurationManager.getConfiguration(cacheType) : null;
CacheConfiguration.CacheObjectTypeConfiguration cacheObjectTypeConfiguration = cacheConfiguration != null ? cacheConfiguration.getForObjectType(targetTypeClass) : null;
StatisticsLevel statisticsLevel = getStatisticsLevel(cacheObjectTypeConfiguration, cacheConfiguration);
boolean traceMiss = CacheConfiguration.getTraceMiss(cacheObjectTypeConfiguration, cacheConfiguration);
boolean tracePass = CacheConfiguration.getTracePass(cacheObjectTypeConfiguration, cacheConfiguration);
ObjectSearchStrategyType searchStrategy = getSearchStrategy();
AbstractSearchExpressionEvaluatorCache cache = getCache();
if (cache == null) {
if (cacheClass != null) {
log("Cache: NULL {} ({})", false, query, targetTypeClass.getSimpleName());
collector.registerNotAvailable(cacheClass, targetTypeClass, statisticsLevel);
}
return executeSearch(null, targetTypeClass, targetTypeQName, query, searchStrategy, additionalAttributeDeltas, params, contextDescription, task, result);
}
assert cacheClass != null && cacheType != null;
if (!cache.supportsObjectType(targetTypeClass)) {
log("Cache: PASS {} ({})", tracePass, query, targetTypeClass.getSimpleName());
cache.registerPass();
collector.registerPass(cacheClass, targetTypeClass, statisticsLevel);
return executeSearch(null, targetTypeClass, targetTypeQName, query, searchStrategy, additionalAttributeDeltas, params, contextDescription, task, result);
}
// noinspection unchecked
List<V> list = cache.getQueryResult(targetTypeClass, query, searchStrategy, params, prismContext);
if (list != null) {
cache.registerHit();
collector.registerHit(cacheClass, targetTypeClass, statisticsLevel);
log("Cache: HIT {} ({})", false, query, targetTypeClass.getSimpleName());
return CloneUtil.clone(list);
}
cache.registerMiss();
collector.registerMiss(cacheClass, targetTypeClass, statisticsLevel);
log("Cache: MISS {} ({})", traceMiss, query, targetTypeClass.getSimpleName());
List<PrismObject> rawResult = new ArrayList<>();
List<V> freshList = executeSearch(rawResult, targetTypeClass, targetTypeQName, query, searchStrategy, additionalAttributeDeltas, params, contextDescription, task, result);
if (!freshList.isEmpty()) {
// we don't want to cache negative results (e.g. if used with focal objects it might mean that they would be attempted to create multiple times)
// noinspection unchecked
cache.putQueryResult(targetTypeClass, query, searchStrategy, params, freshList, rawResult, prismContext);
}
return freshList;
}
Aggregations