@Override
    public SamlIdPMetadataDocument fetch(final Optional<SamlRegisteredService> registeredService) {
        val key = buildCacheKey(registeredService);

        return getMetadataCache().get(key, Unchecked.function(__ -> {
            val metadataDocument = fetchInternal(registeredService);
            if (metadataDocument != null && metadataDocument.isValid()) {
                LOGGER.trace("Fetched and cached SAML IdP metadata document [{}] under key [{}]", metadataDocument, key);
                return metadataDocument;
            }

            LOGGER.trace("SAML IdP metadata document [{}] is considered invalid", metadataDocument);
            return null;
        }));
    }
This is {@link AbstractSamlIdPMetadataLocator}.

@author Misagh Moayyed
@since 5.3.0
support/cas-server-support-saml-idp-core/src/main/java/org/apereo/cas/support/saml/idp/metadata/locator/AbstractSamlIdPMetadataLocator.java