+ // Bound by max and min.
+ if (cacheExp > m_maxCacheDuration)
+ cacheExp = m_maxCacheDuration;
+ else if (cacheExp < m_minCacheDuration)
+ cacheExp = m_minCacheDuration;
+
+ log.info("next refresh of metadata for (%s) no sooner than %u seconds", name.c_str(), cacheExp);
+
+ // Upgrade our lock so we can cache the new metadata.
+ m_lock->unlock();
+ m_lock->wrlock();
+
+ // Notify observers.
+ emitChangeEvent(*entity2);
+
+ // Record the proper refresh time.
+ m_cacheMap[entity2->getEntityID()] = now + cacheExp;
+
+ // Make sure we clear out any existing copies, including stale metadata or if somebody snuck in.
+ cacheExp = SAMLTIME_MAX;
+ indexEntity(entity2.get(), cacheExp, true);
+ entity2.release();
+
+ m_lastUpdate = now;
+
+ // Downgrade back to a read lock.
+ m_lock->unlock();
+ m_lock->rdlock();
+ }
+ catch (exception& e) {
+ log.error("error while resolving entityID (%s): %s", name.c_str(), e.what());
+ // This will return entries that are beyond their cache period,
+ // but not beyond their validity unless that criteria option was set.
+ // If it is a cache-expired entry, bump the cache period to prevent retries.
+ if (entity.first)
+ m_cacheMap[entity.first->getEntityID()] = time(nullptr) + m_minCacheDuration;
+ else if (criteria.entityID_unicode)
+ m_cacheMap[criteria.entityID_unicode] = time(nullptr) + m_minCacheDuration;
+ else {
+ auto_ptr_XMLCh widetemp(name.c_str());
+ m_cacheMap[widetemp.get()] = time(nullptr) + m_minCacheDuration;
+ }
+ log.warn("next refresh of metadata for (%s) no sooner than %u seconds", name.c_str(), m_minCacheDuration);
+ return entity;
+ }