This commit is contained in:
sunkaixuan 2017-10-11 11:23:10 +08:00
parent 371dd1ee24
commit c70059062d
2 changed files with 20 additions and 12 deletions

View File

@ -1,4 +1,5 @@
using SqlSugar;
using SqlSugar.Extensions;
using System;
using System.Collections.Generic;
using System.Linq;
@ -11,40 +12,43 @@ namespace ExtensionsDemo
{
public static void Init()
{
ICacheService myCache = new SqlSugar.Extensions.HttpRuntimeCache();//ICacheService
ICacheService myCache = new HttpRuntimeCache();//ICacheService
SqlSugarClient db = new SqlSugarClient(
new ConnectionConfig()
{
ConnectionString = Config.ConnectionString,
DbType = DbType.SqlServer,
IsAutoCloseConnection = true,
ConfigureExternalServices = new ConfigureExternalServices()
{
DataInfoCacheService = myCache //Setting external cache service
}
SqlSugarClient db = new SqlSugarClient( new ConnectionConfig(){
ConnectionString = Config.ConnectionString,
DbType = DbType.SqlServer,
IsAutoCloseConnection = true,
ConfigureExternalServices = new ConfigureExternalServices()
{
DataInfoCacheService = myCache //Setting external cache service
}
});
for (int i = 0; i < 10000; i++)
{
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("Cache Key Count:"+myCache.GetAllKey<string>().Count());
foreach (var item in myCache.GetAllKey<string>())
{
Console.WriteLine();
Console.WriteLine(item);
Console.WriteLine();
}
db.Deleteable<Student>().Where(it => it.Id == 1).RemoveDataCache().ExecuteCommand();
Console.WriteLine("Cache Key Count:" + myCache.GetAllKey<string>().Count());

View File

@ -50,6 +50,10 @@
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\SqlSugar.Extensions.DataCache\SqlSugar.Extensions.DataCache.csproj">
<Project>{cdb72abe-0336-4730-a195-abf2611deeaa}</Project>
<Name>SqlSugar.Extensions.DataCache</Name>
</ProjectReference>
<ProjectReference Include="..\SqlSugar\SqlSugar.csproj">
<Project>{489bb790-226c-4fad-8d1e-51d72a7ff8e5}</Project>
<Name>SqlSugar</Name>