Skip to content

Commit

Permalink
Invalidate archetype cache on more change types
Browse files Browse the repository at this point in the history
Now we invalidate also when system config or an object template
is changed.
  • Loading branch information
mederly committed Feb 5, 2021
1 parent 7cd6a19 commit f363c89
Showing 1 changed file with 17 additions and 10 deletions.
Expand Up @@ -52,6 +52,15 @@ public class ArchetypeManager implements Cache {
private static final Trace LOGGER = TraceManager.getTrace(ArchetypeManager.class);
private static final Trace LOGGER_CONTENT = TraceManager.getTrace(ArchetypeManager.class.getName() + ".content");

/**
* Cache invalidation is invoked when an object of any of these classes is modified.
*/
private static final Collection<Class<?>> INVALIDATION_RELATED_CLASSES = Arrays.asList(
ArchetypeType.class,
SystemConfigurationType.class,
ObjectTemplateType.class
);

@Autowired private SystemObjectCache systemObjectCache;
@Autowired private PrismContext prismContext;
@Autowired private CacheRegistry cacheRegistry;
Expand Down Expand Up @@ -110,10 +119,7 @@ private <O extends AssignmentHolderType> List<ObjectReferenceType> determineArch
return assignments.stream()
.filter(a -> {
ObjectReferenceType target = a.getTargetRef();
if (target == null) {
return false;
}
return QNameUtil.match(ArchetypeType.COMPLEX_TYPE, target.getType());
return target != null && QNameUtil.match(ArchetypeType.COMPLEX_TYPE, target.getType());
})
.map(AssignmentType::getTargetRef)
.collect(Collectors.toList());
Expand Down Expand Up @@ -300,7 +306,7 @@ private GuiObjectDetailsPageType mergeObjectDetails(ArchetypeAdminGuiConfigurati
List<VirtualContainersSpecificationType> mergedVirtualContainers = mergeVirtualContainers(currentObjectDetails, superObjectDetails);
mergedObjectDetails.getContainer().clear();
mergedObjectDetails.getContainer().addAll(mergedVirtualContainers);
//TODO savemethod, objectForm, relations
//TODO save method, objectForm, relations

return mergedObjectDetails;
}
Expand Down Expand Up @@ -399,6 +405,7 @@ private VirtualContainersSpecificationType mergeVirtualContainer(VirtualContaine
}

private <C extends Containerable> C cloneComplex(C containerable) {
//noinspection unchecked
PrismContainerValue<C> pcv = containerable.asPrismContainerValue().cloneComplex(CloneStrategy.REUSE);
return pcv.asContainerable();
}
Expand Down Expand Up @@ -541,7 +548,7 @@ private IconType mergeIcon(IconType currentIcon, IconType superIcon) {
private List<ItemConstraintType> mergeItemConstraints(List<ItemConstraintType> currentConstraints, List<ItemConstraintType> superConstraints) {
return mergeContainers(currentConstraints, superConstraints,
this::createItemConstraintPredicate,
this::mergeItemContraint);
this::mergeItemConstraint);
}

private Predicate<ItemConstraintType> createItemConstraintPredicate(ItemConstraintType constraint) {
Expand All @@ -553,7 +560,7 @@ private boolean pathsMatch(ItemPathType supperPath, ItemPathType currentPath) {
return supperPath != null && currentPath != null && supperPath.equivalent(currentPath);
}

private ItemConstraintType mergeItemContraint(ItemConstraintType matchedConstraint, ItemConstraintType superConstraint) {
private ItemConstraintType mergeItemConstraint(ItemConstraintType matchedConstraint, ItemConstraintType superConstraint) {
ItemConstraintType mergedConstraint = cloneComplex(matchedConstraint);
if (matchedConstraint.getVisibility() == null) {
mergedConstraint.setVisibility(superConstraint.getVisibility());
Expand Down Expand Up @@ -753,7 +760,7 @@ private ArchetypePolicyType merge(ArchetypePolicyType archetypePolicy, ObjectPol
return resultPolicy;
}

public <O extends ObjectType> ObjectPolicyConfigurationType determineObjectPolicyConfiguration(PrismObject<O> object, OperationResult result) throws SchemaException, ConfigurationException {
private <O extends ObjectType> ObjectPolicyConfigurationType determineObjectPolicyConfiguration(PrismObject<O> object, OperationResult result) throws SchemaException, ConfigurationException {
if (object == null) {
return null;
}
Expand All @@ -776,7 +783,7 @@ public <O extends ObjectType> ExpressionProfile determineExpressionProfile(Prism
/**
* This has to remain static due to use from LensContext. Hopefully it will get refactored later.
*/
public static <O extends ObjectType> ObjectPolicyConfigurationType determineObjectPolicyConfiguration(PrismObject<O> object, SystemConfigurationType systemConfigurationType) throws ConfigurationException {
private static <O extends ObjectType> ObjectPolicyConfigurationType determineObjectPolicyConfiguration(PrismObject<O> object, SystemConfigurationType systemConfigurationType) throws ConfigurationException {
List<String> subTypes = FocusTypeUtil.determineSubTypes(object);
return determineObjectPolicyConfiguration(object.getCompileTimeClass(), subTypes, systemConfigurationType);
}
Expand Down Expand Up @@ -824,7 +831,7 @@ public static <O extends ObjectType> LifecycleStateModelType determineLifecycleM

@Override
public void invalidate(Class<?> type, String oid, CacheInvalidationContext context) {
if (type == null || ArchetypeType.class.equals(type)) {
if (type == null || INVALIDATION_RELATED_CLASSES.contains(type)) {
archetypePolicyCache.clear();
}
}
Expand Down

0 comments on commit f363c89

Please sign in to comment.