Пример #1
0
 public void Clear()
 {
     using (CreateCrossPlatLock(_storageCreationProperties))
     {
         CacheStore.Clear(ignoreExceptions: true);
     }
 }
        /// <summary>
        /// Before cache access
        /// </summary>
        /// <param name="args">Callback parameters from MSAL</param>
        internal void BeforeAccessNotification(TokenCacheNotificationArgs args)
        {
            _logger.LogInformation($"Before access");

            _logger.LogInformation($"Acquiring lock for token cache");

            // OK, we have two nested locks here. We need to maintain a clear ordering to avoid deadlocks.
            // 1. Use the CrossPlatLock which is respected by all processes and is used around all cache accesses.
            // 2. Use _lockObject which is used in UnregisterCache, and is needed for all accesses of _registeredCaches.
            CacheLock = CreateCrossPlatLock(_storageCreationProperties);

            _logger.LogInformation($"Before access, the store has changed");
            var cachedStoreData = CacheStore.ReadData();

            _logger.LogInformation($"Read '{cachedStoreData?.Length}' bytes from storage");

            lock (_lockObject)
            {
                try
                {
                    _logger.LogInformation($"Deserializing the store");
                    args.TokenCache.DeserializeMsalV3(cachedStoreData, shouldClearExistingCache: true);
                }
                catch (Exception e)
                {
                    _logger.LogError($"An exception was encountered while deserializing the {nameof(MsalCacheHelper)} : {e}");
                    _logger.LogError($"No data found in the store, clearing the cache in memory.");

                    // Clear the memory cache without taking the lock over again
                    CacheStore.Clear();
                    throw;
                }
            }
        }
 public void Clear()
 {
     using (CreateCrossPlatLock(_storageCreationProperties))
     {
         CacheStore.Clear();
     }
 }
Пример #4
0
        public void Clear()
        {
            var store = new CacheStore();
            var item  = new TestItem();

            store.Save("test", item);
            store.Clear("test");
            var result = store.Has("test");

            Assert.That(!result);
        }
Пример #5
0
        /// <summary>
        /// After cache access
        /// </summary>
        /// <param name="args">Callback parameters from MSAL</param>
        internal void AfterAccessNotification(TokenCacheNotificationArgs args)
        {
            try
            {
                _logger.LogInformation($"After access");
                byte[] data = null;
                // if the access operation resulted in a cache update
                if (args.HasStateChanged)
                {
                    _logger.LogInformation($"After access, cache in memory HasChanged");
                    try
                    {
                        data = args.TokenCache.SerializeMsalV3();
                    }
                    catch (Exception e)
                    {
                        _logger.LogError($"An exception was encountered while serializing the {nameof(MsalCacheHelper)} : {e}");
                        _logger.LogError($"No data found in the store, clearing the cache in memory.");

                        // The cache is corrupt clear it out
                        CacheStore.Clear(ignoreExceptions: true);
                        throw;
                    }

                    if (data != null)
                    {
                        _logger.LogInformation($"Serializing '{data.Length}' bytes");
                        try
                        {
                            CacheStore.WriteData(data);
                        }
                        catch (Exception)
                        {
                            _logger.LogError($"Could not write the token cache. Ignoring. See previous error message.");
                        }
                    }
                }
            }
            finally
            {
                ReleaseFileLock();
            }
        }
 /// <summary>
 /// Clears the token store
 /// </summary>
 public void Clear()
 {
     CacheStore.Clear();
 }