private async Task ValidateCachedContextAsync()
        {
            using (var guard = new UpgradeableGuard(_refreshLock))
            {
                if (_cacheRefreshing || _nextCachedRefreshTime > DateTime.Now)
                {
                    return;
                }
                guard.UpgradeToWriterLock();
                if (_cacheRefreshing)
                {
                    return;                   // Double-check after writer upgrade
                }
                _cacheRefreshing = true;
            }

            if (_nextCachedRefreshTime <= DateTime.Now)
            {
                await RefreshMetadataAsync();
            }

            using (new WriterGuard(_refreshLock))
            {
                _cacheRefreshing = false;
            }
        }
Пример #2
0
        private async Task <OidcDataManager> ValidateCachedContextAsync()
        {
            using (var guard = new UpgradeableGuard(_refreshLock))
            {
                if (_cacheRefreshing || _options.MetadataRefreshInterval < 0 || _nextCachedRefreshTime > DateTime.Now)
                {
                    return(this);
                }
                guard.UpgradeToWriterLock();
                if (_cacheRefreshing)
                {
                    return(this);                  // Double-check after writer upgrade
                }
                _cacheRefreshing = true;
            }

            if (_options.MetadataRefreshInterval >= 0 && _nextCachedRefreshTime <= DateTime.Now)
            {
                await TryRefreshMetadataAsync();
            }

            using (new WriterGuard(_refreshLock))
            {
                _cacheRefreshing = false;
            }

            return(this);
        }
        private async Task ValidateCachedContextAsync()
        {
            using (var guard = new UpgradeableGuard(_refreshLock))
            {
                if (_cacheRefreshing || _nextCachedRefreshTime > DateTime.Now)
                    return;
                guard.UpgradeToWriterLock();
                if (_cacheRefreshing) return; // Double-check after writer upgrade
                _cacheRefreshing = true;
            }

            if (_nextCachedRefreshTime <= DateTime.Now)
                await RefreshMetadataAsync();

            using (new WriterGuard(_refreshLock))
            {
                _cacheRefreshing = false;
            }
        }