Skip to content

Commit

Permalink
Cache Invalidation: Reverted registration contract
Browse files Browse the repository at this point in the history
  - Autowired contract does not work for cache listeners, since it forms
    loop which spring can not handle.
  • Loading branch information
tonydamage committed Jul 13, 2022
1 parent d94e040 commit 820b94c
Showing 1 changed file with 21 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,23 @@
* be moved to a more appropriate place.
*/
@Component("cacheRegistry")
public class CacheRegistryImpl implements CacheRegistry {
public class CacheRegistryImpl implements CacheListener, CacheRegistry {

private final List<Cache> caches = new ArrayList<>();

@Autowired private CacheDispatcher dispatcher;
@Autowired private PrismContext prismContext;

@PostConstruct
public void registerListener() {
dispatcher.registerCacheListener(this);
}

@PreDestroy
public void unregisterListener() {
dispatcher.unregisterCacheListener(this);
}

@Override
public synchronized void registerCache(Cache cache) {
if (!caches.contains(cache)) {
Expand All @@ -49,6 +59,16 @@ public synchronized void unregisterCache(Cache cache) {
caches.remove(cache);
}

@Override
public <O extends ObjectType> void invalidate(Class<O> type, String oid, boolean clusterwide,
CacheInvalidationContext context) {
// We currently ignore clusterwide parameter, because it's used by ClusterCacheListener only.
// So we assume that the invalidation event - from this point on - is propagated only locally.
for (Cache cache : caches) {
cache.invalidate(type, oid, context);
}
}

@Override
public CachesStateInformationType getStateInformation() {
CachesStateInformationType rv = new CachesStateInformationType(prismContext);
Expand Down

0 comments on commit 820b94c

Please sign in to comment.