diff --git a/NewLife.Core/Caching/Cache.cs b/NewLife.Core/Caching/Cache.cs
index ec1e03e2a..acda9d5be 100644
--- a/NewLife.Core/Caching/Cache.cs
+++ b/NewLife.Core/Caching/Cache.cs
@@ -36,6 +36,16 @@ public abstract class Cache : DisposeBase, ICache
#region 构造
/// 构造函数
protected Cache() => Name = GetType().Name.TrimEnd("Cache");
+
+ /// 销毁。释放资源
+ ///
+ protected override void Dispose(Boolean disposing)
+ {
+ base.Dispose(disposing);
+
+ _keys = null;
+ //_keys2 = null;
+ }
#endregion
#region 基础操作
@@ -367,12 +377,12 @@ public virtual Int64 Bench(Boolean rand = false, Int32 batch = 0)
// 提前准备Keys,减少性能测试中的干扰
var key = "bstr_";
- var key2 = "bint_";
+ //var key2 = "bint_";
var max = cpu > 64 ? cpu : 64;
var maxTimes = times * max;
if (!rand) maxTimes = max;
_keys = new String[maxTimes];
- _keys2 = new String[maxTimes];
+ //_keys2 = new String[maxTimes];
var sb = new StringBuilder();
for (var i = 0; i < _keys.Length; i++)
@@ -382,10 +392,10 @@ public virtual Int64 Bench(Boolean rand = false, Int32 batch = 0)
sb.Append(i);
_keys[i] = sb.ToString();
- sb.Clear();
- sb.Append(key2);
- sb.Append(i);
- _keys2[i] = sb.ToString();
+ //sb.Clear();
+ //sb.Append(key2);
+ //sb.Append(i);
+ //_keys2[i] = sb.ToString();
}
// 单线程
@@ -417,7 +427,7 @@ public virtual Int64 Bench(Boolean rand = false, Int32 batch = 0)
protected virtual Int32 GetTimesPerThread(Boolean rand, Int32 batch) => 10_000;
private String[]? _keys;
- private String[]? _keys2;
+ //private String[]? _keys2;
/// 使用指定线程测试指定次数
/// 次数
/// 线程
@@ -444,12 +454,12 @@ public virtual Int64 BenchOne(Int64 times, Int32 threads, Boolean rand, Int32 ba
// 读取测试
rs += BenchGet(_keys, times, threads, rand, batch);
+ // 累加测试
+ rs += BenchInc(_keys!, times, threads, rand, batch);
+
// 删除测试
rs += BenchRemove(_keys, times, threads, rand, batch);
- // 累加测试
- rs += BenchInc(_keys2!, times, threads, rand, batch);
-
return rs;
}
diff --git a/NewLife.Core/Caching/MemoryCache.cs b/NewLife.Core/Caching/MemoryCache.cs
index 70a4a631d..abf7f8753 100644
--- a/NewLife.Core/Caching/MemoryCache.cs
+++ b/NewLife.Core/Caching/MemoryCache.cs
@@ -17,7 +17,7 @@ public class KeyEventArgs : CancelEventArgs
public String Key { get; set; } = null!;
}
-/// 默认字典缓存
+/// 内存缓存。并行字典实现,峰值性能10亿ops
public class MemoryCache : Cache
{
#region 属性
@@ -497,7 +497,22 @@ protected class CacheItem
/// 设置数值和过期时间
///
/// 过期时间,秒
- public void Set(T value, Int32 expire) => Set(value, TimeSpan.FromSeconds(expire));
+ public void Set(T value, Int32 expire)
+ {
+ var type = typeof(T);
+ TypeCode = type.GetTypeCode();
+
+ if (IsInt())
+ _valueLong = value.ToLong();
+ else
+ _value = value;
+
+ var now = VisitTime = Runtime.TickCount64;
+ if (expire <= 0)
+ ExpiredTime = Int64.MaxValue;
+ else
+ ExpiredTime = now + expire * 1000;
+ }
/// 设置数值和过期时间
///
diff --git a/Test/Program.cs b/Test/Program.cs
index 23066063e..0486ee387 100644
--- a/Test/Program.cs
+++ b/Test/Program.cs
@@ -204,8 +204,12 @@ private static void Test3()
private static void Test4()
{
- var v = Rand.NextBytes(32);
- Console.WriteLine(v.ToBase64());
+ // 提升进程优先级
+ var p = Process.GetCurrentProcess();
+ p.PriorityClass = ProcessPriorityClass.High;
+
+ //var v = Rand.NextBytes(32);
+ //Console.WriteLine(v.ToBase64());
ICache ch = null;
//ICache ch = new DbCache();