@Override
    public List<RegisteredService> updateLoadedRegisteredServicesFromCache(final List<RegisteredService> services,
                                                                           final ServiceRegistry serviceRegistry) {
        val cachedServices = distributedCacheManager.getAll()
            .stream()
            .sorted(Comparator.<DistributedCacheObject>comparingLong(DistributedCacheObject::getTimestamp).reversed())
            .filter(CollectionUtils.distinctByKey(service -> service.getValue().getId()))
            .toList();
        for (val entry : cachedServices) {
            val cachedService = entry.getValue();
            LOGGER.debug("Found cached service definition [{}] in the replication cache [{}]",
                cachedService, distributedCacheManager.getName());

            if (isRegisteredServiceMarkedAsDeletedInCache(entry)) {
                LOGGER.debug("Service found in the cache [{}] is marked as a deleted service. CAS will update the service registry "
                             + "of this CAS node to remove the local service, if found.", cachedService);
                serviceRegistry.delete(cachedService);
                distributedCacheManager.remove(cachedService, entry, true);
                continue;
            }

            val matchingService = services.stream()
                .filter(svc -> svc.getId() == cachedService.getId())
                .findFirst()
                .orElse(null);

            if (matchingService != null) {
                updateServiceRegistryWithMatchingService(services, cachedService, matchingService, serviceRegistry);
            } else {
                updateServiceRegistryWithNoMatchingService(services, cachedService, serviceRegistry);
            }
        }
        distributedCacheManager.clear();
        return services;
    }
This is {@link DefaultRegisteredServiceReplicationStrategy}.

@author Misagh Moayyed
@since 5.2.0
core/cas-server-core-services-registry/src/main/java/org/apereo/cas/services/replication/DefaultRegisteredServiceReplicationStrategy.java