静态字典缓存和常用的泛型缓存的性能相比,泛型缓存性能是非常优异的。
泛型缓存是JIT产生全新的类,内存直接分配,由CPU查找内存地址。
静态字典缓存需要根据地址去寻址,去查找。
public class GenericCache<T>
{
static GenericCache()
{
_CachedValue = string.Format("{0}_{1}",
typeof(T).FullName, DateTime.Now.ToString("yyyyMMddHHmmss.fff"));
}
private static string _CachedValue = "";
public static string GetCache()
{
return _CachedValue;
}
}
泛型缓存的 T 就是缓存的 Key 值。