@Override
    public long expireAfterCreate(
        final @NonNull SamlRegisteredServiceCacheKey cacheKey,
        final @NonNull CachedMetadataResolverResult cacheResult,
        final long currentTime) {
        val service = cacheKey.getRegisteredService();
        val duration = getCacheDurationForServiceProvider(service, cacheResult);
        if (duration >= 0) {
            LOGGER.trace("Metadata cache duration for [{}] is [{}]", service.getName(), duration);
            return duration;
        }
        LOGGER.trace("Metadata for [{}] does not define caching policies", service.getName());
        if (StringUtils.isNotBlank(service.getMetadataExpirationDuration())) {
            LOGGER.debug("Service [{}] defines a cache expiration duration of [{}]", service.getName(), service.getMetadataExpirationDuration());
            return Beans.newDuration(service.getMetadataExpirationDuration()).toNanos();
        }
        val expPolicy = service.getExpirationPolicy();
        if (expPolicy != null && StringUtils.isNotBlank(expPolicy.getExpirationDate())) {
            val expDate = DateTimeUtils.localDateTimeOf(expPolicy.getExpirationDate());
            @SuppressWarnings("JavaTimeDefaultTimeZone")
            val now = LocalDateTime.now(Clock.systemDefaultZone());
            val result = Duration.between(now, expDate).toNanos();
            LOGGER.trace("Using the difference between now [{}] and "
                         + "expiration date [{}] from the service expiration policy: [{}]", now, expDate, result);
            return result;
        }

        LOGGER.trace("Service [{}] does not define caching policies. Falling back onto default...", service.getName());
        return defaultExpiration.toNanos();
    }
This is {@link SamlRegisteredServiceMetadataExpirationPolicy}.

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