aliyun / aliyun-openapi-net-sdk

Alibaba Cloud SDK for .NET
https://www.nuget.org/profiles/aliyun-openapi-sdk
Other
541 stars 625 forks source link

sdk_core库中Dictionary处理有问题,会导致cpu 100% #43

Closed ikvm closed 5 years ago

ikvm commented 6 years ago

System.Collections.Generic.Dictionary`2[[System.Canon, mscorlib],[System.DateTime, mscorlib]].FindEntry(System.Canon) Aliyun.Acs.Core.Utils.CacheTimeHelper.AddLastClearTimePerProduct

xiaoyuvax commented 6 years ago

改成下面就好了: ` namespace Aliyun.Acs.Core.Utils { public class CacheTimeHelper { private static ConcurrentDictionary<String, DateTime> lastClearTimePerProduct = new ConcurrentDictionary<string, DateTime>(); private const int ENDPOINT_CACHE_TIME = 3600; //Seconds

    public static bool CheckCacheIsExpire(String product, String regionId)
    {
        DateTime lastClearTime;
        String key = product + "_" + regionId;

        if (lastClearTimePerProduct.ContainsKey(key))
        {
            lastClearTime = lastClearTimePerProduct[key];
        }
        else
        {
            lastClearTime = DateTime.Now;
            lastClearTimePerProduct.TryAdd(key, lastClearTime);
        }

        TimeSpan ts = DateTime.Now - lastClearTime;

        if (ENDPOINT_CACHE_TIME < ts.TotalSeconds)
        {
            return true;
        }

        return false;
    }

    public static void AddLastClearTimePerProduct(String product, String regionId, DateTime lastClearTime)
    {
        String key = product + "_" + regionId;

        if (lastClearTimePerProduct.ContainsKey(key))
        {
            lastClearTimePerProduct.TryRemove(key,out DateTime dt);
        }
        lastClearTimePerProduct.TryAdd(key, lastClearTime);
    }
}

} `