从山证v2.3.0拷贝
This commit is contained in:
@@ -0,0 +1,83 @@
|
||||
namespace YLErp.Modules.DataCacheModule
|
||||
{
|
||||
public static partial class DataCacheManager
|
||||
{
|
||||
/// <summary>
|
||||
/// 场内期权基础数据
|
||||
/// </summary>
|
||||
class ExchangeListOptionDataSource : GenericeCachedDataSource<ExchangeListOption>, Abstract.IDataSourceKey2<ExchangeListOption>
|
||||
{
|
||||
public override string TableName => nameof(ExchangeListOption);
|
||||
|
||||
readonly Dictionary<string, ExchangeListOption> _dicEx;
|
||||
|
||||
public ExchangeListOptionDataSource()
|
||||
{
|
||||
_dicEx = new Dictionary<string, ExchangeListOption>(StringComparer.OrdinalIgnoreCase);
|
||||
|
||||
AfterUpdate = data =>
|
||||
{
|
||||
if (!string.IsNullOrWhiteSpace(data?.ContractCode))
|
||||
{
|
||||
_dicEx[data.ContractCode] = data;
|
||||
}
|
||||
};
|
||||
|
||||
AfterRemove = data =>
|
||||
{
|
||||
if (!string.IsNullOrWhiteSpace(data?.ContractCode))
|
||||
{
|
||||
_dicEx.Remove(data.ContractCode);
|
||||
}
|
||||
};
|
||||
|
||||
//使用近1个月的数据作为缓存
|
||||
var date = DateTime.Today.AddDays(-30);
|
||||
Filter = PredicateBuilder.Create<ExchangeListOption>(n => n.MaturityDate > date);
|
||||
}
|
||||
|
||||
public ExchangeListOption GetData(string keyId)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(keyId))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
lock (this)
|
||||
{
|
||||
if (_dicEx.TryGetValue(keyId, out ExchangeListOption data))
|
||||
{
|
||||
return data;
|
||||
}
|
||||
|
||||
using (var db = DbContextFactory.GetYLDbContext())
|
||||
{
|
||||
var exopt = db.exchange_list_option.AsNoTracking().FirstOrDefault(n => n.ContractCode == keyId);
|
||||
if (exopt != null)
|
||||
{
|
||||
_dic[exopt.id] = exopt;
|
||||
_dicEx[exopt.ContractCode] = exopt;
|
||||
}
|
||||
return exopt?.Clone();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override void ResetDataSource()
|
||||
{
|
||||
base.ResetDataSource();
|
||||
|
||||
_dicEx.Clear();
|
||||
}
|
||||
|
||||
//---------------------------------------------
|
||||
|
||||
public static readonly ExchangeListOptionDataSource Default;
|
||||
|
||||
static ExchangeListOptionDataSource()
|
||||
{
|
||||
Default = new ExchangeListOptionDataSource();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user