Beispiel #1
0
        private static void Collect(object threadId)
        {
            while (true)
            {
                try
                {
                    var cacheValues = Cache.Values;
                    cacheValues = cacheValues.OrderBy(p => p.Item3).ToList();
                    foreach (var cacheValue in cacheValues)
                    {
                        if ((cacheValue.Item3 - DateTime.Now).Seconds <= 0)
                        {
                            Cache.TryRemove(cacheValue.Item1, out _);
                        }
                    }

                    Thread.Sleep(TaskInterval * 60 * 1000);
                }
                catch
                {
                    Dispose();
                    DefaultGCThreadProvider.AddThread(Collect);
                }
            }
            // ReSharper disable once FunctionNeverReturns
        }
Beispiel #2
0
 static DefaultMemoryCache()
 {
     try
     {
         DefaultGCThreadProvider.AddThread(Collect);
     }
     catch (Exception err)
     {
         throw new CachingException(err.Message, err);
     }
 }