This commit is contained in:
sunkaixuan
2017-09-29 14:28:37 +08:00
parent adccc1767e
commit 4d242cd08f
6 changed files with 86 additions and 6 deletions

View File

@@ -1006,17 +1006,23 @@ namespace SqlSugar
{
List<TResult> result = null;
var sqlObj = this.ToSql();
var isComplexModel = QueryBuilder.IsComplexModel(sqlObj.Key);
var entityType = typeof(TResult);
result = GetData<TResult>(sqlObj, isComplexModel, entityType);
RestoreMapping();
SetContextModel(result, entityType);
if (IsCache)
{
var cacheService = this.Context.CurrentConnectionConfig.ConfigureExternalServices.DataInfoCache;
result = CacheSchemeMain.GetOrCreate<List<TResult>>(cacheService, this.Context, this.QueryBuilder,()=> { return GetData<TResult>(sqlObj); });
}
else
{
result = GetData<TResult>(sqlObj);
}
return result;
}
protected List<TResult> GetData<TResult>(KeyValuePair<string, List<SugarParameter>> sqlObj, bool isComplexModel, Type entityType)
protected List<TResult> GetData<TResult>(KeyValuePair<string, List<SugarParameter>> sqlObj)
{
List<TResult> result;
var isComplexModel = QueryBuilder.IsComplexModel(sqlObj.Key);
var entityType = typeof(TResult);
var dataReader = this.Db.GetDataReader(sqlObj.Key, sqlObj.Value.ToArray());
if (typeof(TResult) == typeof(ExpandoObject))
{
@@ -1030,6 +1036,8 @@ namespace SqlSugar
{
result = this.Bind.DataReaderToList<TResult>(entityType, dataReader, QueryBuilder.SelectCacheKey);
}
RestoreMapping();
SetContextModel(result, entityType);
return result;
}

View File

@@ -0,0 +1,20 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace SqlSugar
{
internal class CacheEngines
{
public string GetCacheMapping()
{
return null;
}
public string GetCacheData()
{
return null;
}
}
}

View File

@@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace SqlSugar
{
internal class CacheKeyBuider
{
public static CacheKey GetKey(SqlSugarClient context, QueryBuilder queryBuilder)
{
throw new NotImplementedException();
}
}
}

View File

@@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace SqlSugar
{
internal class CacheSchemeMain
{
public static T GetOrCreate<T>(ICacheService cacheService, SqlSugarClient context, QueryBuilder queryBuilder,Func<T> getData)
{
string key = CacheKeyBuider.GetKey(context,queryBuilder).ToString();
var result= cacheService.GetOrCreate(key, () => getData());
return result;
}
}
}

View File

@@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace SqlSugar
{
public class CacheKey
{
public new string ToString() {
return "";
}
}
}

View File

@@ -72,6 +72,10 @@
<Compile Include="Abstract\FilterProvider\FilterProvider.cs" />
<Compile Include="Abstract\InsertableProvider\InsertableProvider.cs" />
<Compile Include="Abstract\DeleteProvider\DeleteableProvider.cs" />
<Compile Include="CacheScheme\CacheEngines.cs" />
<Compile Include="CacheScheme\CacheKeyBuider.cs" />
<Compile Include="CacheScheme\CacheSchemeMain.cs" />
<Compile Include="Entities\CacheKey.cs" />
<Compile Include="Enum\DbType.cs" />
<Compile Include="ExpressionsToSql\Subquery\Items\ISubOperation.cs" />
<Compile Include="ExpressionsToSql\Subquery\Items\SubAnd.cs" />
@@ -252,6 +256,7 @@
<Content Include="References\Oracle.ManagedDataAccess.dll" />
<Content Include="References\System.Data.SQLite.dll" />
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.