Update data cache

This commit is contained in:
SUNKAIXUAN 2021-03-27 13:59:02 +08:00
parent fecffff14c
commit 23adbefe94
5 changed files with 31 additions and 15 deletions

View File

@ -33,21 +33,16 @@ namespace ExtensionsDemo
}
});
for (int i = 0; i < 10000; i++)
db.Aop.OnLogExecuted = (s, p) =>
{
db.Queryable<Student>().Where(it => it.Id > 0).WithCache().ToList();
}
db.Queryable<Student, Student>((s1, s2) => s1.Id == s2.Id).Select(s1 => s1).WithCache().ToList();
db.Queryable<Student, Student>((s1, s2) => new object[] {
JoinType.Left,s1.Id==s2.Id
}).Select(s1 => s1).WithCache().ToList();
Console.WriteLine(s);
};
db.CodeFirst.InitTables<Student>();
db.Insertable(new Student() { CreateTime = DateTime.Now, Name= "a",SchoolId=0 }).ExecuteCommand();
var x=db.Queryable<Student>().WithCache().ToDictionaryList();
// db.Queryable<Student>().Select("1 as idx").WithCache().ToList();
Console.WriteLine("Cache Key Count:" + myCache.GetAllKey<string>().Count());
foreach (var item in myCache.GetAllKey<string>())
@ -56,6 +51,7 @@ namespace ExtensionsDemo
Console.WriteLine(item);
Console.WriteLine();
}
db.Deleteable<Student>().Where(it => it.Id == 1).RemoveDataCache().ExecuteCommand();

View File

@ -8,6 +8,6 @@ namespace ExtensionsDemo
{
public class Config
{
public static string ConnectionString = "server=.;uid=sa;pwd=haosql;database=SqlSugar4XTest";
public static string ConnectionString = "server=.;uid=sa;pwd=sasa;database=SqlSugar4XTest";
}
}

View File

@ -751,6 +751,9 @@ namespace SqlSugar
var result = InstanceFactory.GetQueryable<TResult>(this.Context.CurrentConnectionConfig);
result.Context = this.Context;
result.SqlBuilder = this.SqlBuilder;
result.QueryBuilder.ResultType = this.QueryBuilder.ResultType;
result.IsCache = this.IsCache;
result.CacheTime = this.CacheTime;
QueryBuilder.SelectValue = selectValue;
if (this.IsAs)
{
@ -954,7 +957,7 @@ namespace SqlSugar
public virtual DataTable ToDataTable()
{
QueryBuilder.ResultType = typeof(DataTable);
QueryBuilder.ResultType = typeof(SugarCacheDataTable);
InitMapping();
var sqlObj = this.ToSql();
RestoreMapping();
@ -1003,6 +1006,7 @@ namespace SqlSugar
public Dictionary<string, object> ToDictionary(Expression<Func<T, object>> key, Expression<Func<T, object>> value)
{
this.QueryBuilder.ResultType = typeof(SugarCacheDictionary);
var keyName = QueryBuilder.GetExpressionValue(key, ResolveExpressType.FieldSingle).GetResultString();
var valueName = QueryBuilder.GetExpressionValue(value, ResolveExpressType.FieldSingle).GetResultString();
var result = this.Select<KeyValuePair<string, object>>(keyName + "," + valueName).ToList().ToDictionary(it => it.Key.ObjToString(), it => it.Value);
@ -1010,6 +1014,7 @@ namespace SqlSugar
}
public async Task<Dictionary<string, object>> ToDictionaryAsync(Expression<Func<T, object>> key, Expression<Func<T, object>> value)
{
this.QueryBuilder.ResultType = typeof(SugarCacheDictionary);
var keyName = QueryBuilder.GetExpressionValue(key, ResolveExpressType.FieldSingle).GetResultString();
var valueName = QueryBuilder.GetExpressionValue(value, ResolveExpressType.FieldSingle).GetResultString();
var list = await this.Select<KeyValuePair<string, object>>(keyName + "," + valueName).ToListAsync();
@ -1325,7 +1330,7 @@ namespace SqlSugar
}
public async Task<DataTable> ToDataTableAsync()
{
QueryBuilder.ResultType = typeof(DataTable);
QueryBuilder.ResultType = typeof(SugarCacheDataTable);
InitMapping();
var sqlObj = this.ToSql();
RestoreMapping();

View File

@ -63,4 +63,17 @@ namespace SqlSugar
}
}
}
internal class SugarCacheDictionary
{
}
internal class SugarCacheDictionaryList
{
}
internal class SugarCacheDataTable
{
}
}

View File

@ -14,6 +14,8 @@ namespace SqlSugar
SqlSugarProvider Context { get; set; }
ISqlBuilder SqlBuilder { get; set; }
QueryBuilder QueryBuilder { get; set; }
bool IsCache { get; set; }
int CacheTime { get; set; }
ISugarQueryable<T> Clone();
ISugarQueryable<T> AS<T2>(string tableName);
ISugarQueryable<T> AS(string tableName);