Skip to content

Commit

Permalink
Cache Invalidation: Introduced InvalidationListener and event specifi…
Browse files Browse the repository at this point in the history
…cation
  • Loading branch information
tonydamage committed Jul 13, 2022
1 parent c331c65 commit 028bbf9
Show file tree
Hide file tree
Showing 3 changed files with 106 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*
* Copyright (c) 2022 Evolveum and contributors
*
* This work is dual-licensed under the Apache License 2.0
* and European Union Public License. See LICENSE file for details.
*/

package com.evolveum.midpoint.repo.api;

import java.util.Collections;
import java.util.EnumSet;
import java.util.Set;

import org.jetbrains.annotations.NotNull;

import com.evolveum.midpoint.prism.delta.ChangeType;
import com.evolveum.midpoint.prism.path.ItemPath;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType;

public class CacheInvalidationEventSpecification {

public static final Set<ChangeType> ALL_CHANGES = Collections.unmodifiableSet(EnumSet.allOf(ChangeType.class));
public static final Set<ChangeType> MODIFY_DELETE = Collections.unmodifiableSet(EnumSet.of(ChangeType.MODIFY, ChangeType.DELETE));
public static final Set<ItemPath> ALL_PATHS = Collections.singleton(ItemPath.EMPTY_PATH);

public static final Set<CacheInvalidationEventSpecification> ALL_AVAILABLE_EVENTS = Collections.singleton(of(ObjectType.class, ALL_CHANGES));



private final Class<? extends ObjectType> objectType;
private final Set<ItemPath> paths;
private final Set<ChangeType> changeTypes;


protected CacheInvalidationEventSpecification(Class<? extends ObjectType> objectType, Set<ItemPath> paths,
Set<ChangeType> changeTypes) {
this.objectType = objectType;
this.paths = paths;
this.changeTypes = changeTypes;
}

public static CacheInvalidationEventSpecification of(Class<? extends ObjectType> type, Set<ChangeType> changes) {
return of(type, null, changes);
}

public static CacheInvalidationEventSpecification of(Class<? extends ObjectType> type, Set<ItemPath> paths,
Set<ChangeType> changes) {
if (paths == null) {
paths = ALL_PATHS;
}
return new CacheInvalidationEventSpecification(type, paths, changes);
}

@NotNull
public Class<? extends ObjectType> getObjectType() {
return objectType;
}

@NotNull
Set<ItemPath> getPaths() {
return paths;
}

@NotNull
Set<ChangeType> getChangeTypes() {
return changeTypes;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Copyright (c) 2022 Evolveum and contributors
*
* This work is dual-licensed under the Apache License 2.0
* and European Union Public License. See LICENSE file for details.
*/

package com.evolveum.midpoint.repo.api;

import java.util.Collection;

import com.evolveum.midpoint.CacheInvalidationContext;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType;

public interface CacheInvalidationListener {

Collection<CacheInvalidationEventSpecification> getEventSpecifications();

/**
* Invalidates given object(s) in all relevant caches.
* @param type Type of object (null means all types).
* @param oid OID of object (null means all object(s) of given type(s)).
* @param clusterwide Whether to distribute this event clusterwide.
* @param context Context of the invalidation request (optional).
*/
<O extends ObjectType> void invalidate(Class<O> type, String oid, boolean clusterwide, CacheInvalidationContext context);

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@

package com.evolveum.midpoint.repo.api;

import java.util.Collection;

import com.evolveum.midpoint.CacheInvalidationContext;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType;

public interface CacheListener {
@Deprecated
public interface CacheListener extends CacheInvalidationListener {

@Override
default Collection<CacheInvalidationEventSpecification> getEventSpecifications() {
return CacheInvalidationEventSpecification.ALL_AVAILABLE_EVENTS;
}

/**
* Invalidates given object(s) in all relevant caches.
* @param type Type of object (null means all types).
* @param oid OID of object (null means all object(s) of given type(s)).
* @param clusterwide Whether to distribute this event clusterwide.
* @param context Context of the invalidation request (optional).
*/
<O extends ObjectType> void invalidate(Class<O> type, String oid, boolean clusterwide, CacheInvalidationContext context);
}

0 comments on commit 028bbf9

Please sign in to comment.