/// <summary> /// Handles the background cache maintenance. /// </summary> /// <param name="ar">The <see cref="IAsyncResult" />.</param> private static void OnCacheTimer(IAsyncResult ar) { AsyncTimer.EndTimer(ar); try { lock (cache) { // Handle expired cache entries List <MD5Key> delList = new List <MD5Key>(); DateTime now = SysTime.Now; foreach (MD5Key key in cache.Keys) { var entry = cache[key]; if (entry.TTD <= now) { // Expired delList.Add(key); LogCachedEntry(entry); } } foreach (MD5Key key in delList) { cache.Remove(key); } } } finally { AsyncTimer.BeginTimer(TimeSpan.FromMinutes(1), onTimer, null); } }