靜態字典緩存和常用的泛型緩存的性能相比,泛型緩存性能是非常優異的。
泛型緩存是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 值。