Commit 903c2a03 authored by justcoding121's avatar justcoding121

use ConcurrentDictionary explicitly

parent 63d18c31
...@@ -90,7 +90,7 @@ namespace Titanium.Web.Proxy.Network ...@@ -90,7 +90,7 @@ namespace Titanium.Web.Proxy.Network
/// <summary> /// <summary>
/// Cache dictionary /// Cache dictionary
/// </summary> /// </summary>
private readonly IDictionary<string, CachedCertificate> certificateCache; private readonly ConcurrentDictionary<string, CachedCertificate> certificateCache;
private readonly Action<Exception> exceptionFunc; private readonly Action<Exception> exceptionFunc;
...@@ -498,10 +498,11 @@ namespace Titanium.Web.Proxy.Network ...@@ -498,10 +498,11 @@ namespace Titanium.Web.Proxy.Network
{ {
//this is ConcurrentDictionary //this is ConcurrentDictionary
//if key exists it will silently handle; no need for locking //if key exists it will silently handle; no need for locking
certificateCache.Add(certificateName, new CachedCertificate certificateCache.TryAdd(certificateName, new CachedCertificate
{ {
Certificate = certificate Certificate = certificate
}); });
} }
...@@ -528,8 +529,9 @@ namespace Titanium.Web.Proxy.Network ...@@ -528,8 +529,9 @@ namespace Titanium.Web.Proxy.Network
var outdated = certificateCache.Where(x => x.Value.LastAccess < cutOff).ToList(); var outdated = certificateCache.Where(x => x.Value.LastAccess < cutOff).ToList();
CachedCertificate removed;
foreach (var cache in outdated) foreach (var cache in outdated)
certificateCache.Remove(cache.Key); certificateCache.TryRemove(cache.Key, out removed);
//after a minute come back to check for outdated certificates in cache //after a minute come back to check for outdated certificates in cache
await Task.Delay(1000 * 60); await Task.Delay(1000 * 60);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment