docs: protected long getCacheDurationForServiceProvider(final SamlRegisteredService service, final MetadataResolver chainingMetadataResolver) {
          try {
              val set = new CriteriaSet();
              set.add(new EntityIdCriterion(service.getServiceId()));
              set.add(new EntityRoleCriterion(SPSSODescriptor.DEFAULT_ELEMENT_NAME));
              val entitySp = chainingMetadataResolver.resolveSingle(set);
              if (entitySp != null && entitySp.getCacheDuration() != null) {
                  LOGGER.debug("Located cache duration [{}] specified in SP metadata for [{}]", entitySp.getCacheDuration(), entitySp.getEntityID());
                  return TimeUnit.MILLISECONDS.toNanos(entitySp.getCacheDuration());
              }
  
              set.clear();
              set.add(new EntityIdCriterion(service.getServiceId()));
              val entity = chainingMetadataResolver.resolveSingle(set);
              if (entity != null && entity.getCacheDuration() != null) {
                  LOGGER.debug("Located cache duration [{}] specified in entity metadata for [{}]", entity.getCacheDuration(), entity.getEntityID());
                  return TimeUnit.MILLISECONDS.toNanos(entity.getCacheDuration());
              }
          } catch (final Exception e) {
              LOGGER.debug(e.getMessage(), e);
          }
          return -1;
      }