using System.Collections.Concurrent;
using Util.Data.Sql.Builders;
using Util.Data.Sql.Builders.Caches;
namespace Util.Data.Sql.Tests.Samples;
///
/// 测试列缓存
///
public class TestColumnCache : ColumnCacheBase {
///
/// 列名缓存
///
private readonly ConcurrentDictionary _cache;
///
/// 初始化测试列缓存
///
public TestColumnCache() : this( TestDialect.Instance ) {
}
///
/// 初始化测试列缓存
///
public TestColumnCache( IDialect dialect ) : base( dialect ) {
_cache = new ConcurrentDictionary();
}
///
/// 测试列缓存实例
///
public static readonly IColumnCache Instance = new TestColumnCache();
///
/// 从缓存中获取处理后的列集合
///
/// 列集合
public override string GetSafeColumns( string columns ) {
return _cache.GetOrAdd( columns.GetHashCode(), key => NormalizeColumns( columns ) );
}
///
/// 从缓存中获取处理后的列
///
/// 列
public override string GetSafeColumn( string column ) {
return _cache.GetOrAdd( column.GetHashCode(), key => NormalizeColumn( column ) );
}
}