@Override
    public CachedMetadataResolverResult resolve(final SamlRegisteredService service, final CriteriaSet criteriaSet) throws Exception {
        val metadataLocation = SpringExpressionLanguageValueResolver.getInstance().resolve(service.getMetadataLocation());
        LOGGER.debug("Resolving metadata for [{}] at [{}]", service.getName(), metadataLocation);
        val cacheKey = new SamlRegisteredServiceCacheKey(service, criteriaSet);
        return FunctionUtils.doAndRetry(retryContext -> {
            LOGGER.debug("Locating cached metadata resolver using key [{}] for service [{}]. Attempt [{}]",
                cacheKey.getId(), service.getName(), retryContext.getRetryCount());
            val queryResult = locateAndCacheMetadataResolver(service, criteriaSet, cacheKey);
            val result = isMetadataResolverAcceptable(queryResult, criteriaSet);
            if (!result.isValid()) {
                val count = countResolvableEntityDescriptors(result);
                if (count == 1) {
                    invalidate(service, criteriaSet);
                }
                LOGGER.warn("SAML metadata resolver [{}] obtained from the cache is "
                        + "unable to produce/resolve valid metadata from [{}]. Metadata resolver cache entry with key [{}] "
                        + "has been invalidated. Attempt: [#{}]",
                    result.getResult().getMetadataResolver().getId(), metadataLocation,
                    cacheKey.getId(), retryContext.getRetryCount());
                throw new SamlException("Unable to locate a valid SAML metadata resolver for "
                    + metadataLocation + " to locate " + criteriaSet);
            }
            return queryResult.getResult();
        }, casProperties.getAuthn().getSamlIdp().getMetadata().getCore().getMaximumRetryAttempts());
    }
An adaptation of metadata resolver which handles the resolution of metadata resources
inside a cache. It basically is a fancy wrapper around a cache, and constructs the cache
semantics before processing the resolution of metadata for a SAML service.

@author Misagh Moayyed
@since 5.0.0
support/cas-server-support-saml-idp-metadata/src/main/java/org/apereo/cas/support/saml/services/idp/metadata/cache/SamlRegisteredServiceDefaultCachingMetadataResolver.java