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;
        }
Example #2
0
 public UpgradedGuard(UpgradeableGuard parentGuard)
 {
     _parentGuard = parentGuard;
     _writerLock  = new WriterGuard(_parentGuard._readerWriterLock);
 }
 public UpgradedGuard(UpgradeableGuard parentGuard)
 {
     _parentGuard = parentGuard;
     _writerLock = new WriterGuard(_parentGuard._readerWriterLock);
 }