Add db.DataCache

This commit is contained in:
SUNKAIXUAN
2021-03-27 15:17:10 +08:00
parent 391015050d
commit 353a010d48
5 changed files with 72 additions and 1 deletions

View File

@@ -0,0 +1,43 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SqlSugar
{
public class SugarCacheProvider
{
public ICacheService Servie { get; set; }
public void RemoveDataCache(string likeString)
{
if (Servie == null) return;
CacheSchemeMain.RemoveCacheByLike(Servie, likeString);
}
public List<string> GetAllKey()
{
if (Servie == null) return new List<string>();
return Servie.GetAllKey<string>()?.ToList();
}
public void Add(string key,object value)
{
if (Servie == null) return;
Servie.Add(key,value,60*60*24*100);
}
public void Add(string key, object value,int seconds)
{
if (Servie == null) return;
Servie.Add(key, value,seconds);
}
public T Get<T>(string key)
{
if (Servie == null) return default(T);
return Servie.Get<T>(key);
}
}
}

View File

@@ -1069,5 +1069,21 @@ namespace SqlSugar
}
#endregion
#region Cache
public SugarCacheProvider DataCache
{
get {
var services=this.CurrentConnectionConfig.ConfigureExternalServices;
if (services == null)
return new SugarCacheProvider();
if (services.DataInfoCacheService == null)
return new SugarCacheProvider();
SugarCacheProvider cache = new SugarCacheProvider();
cache.Servie=services.DataInfoCacheService;
return cache;
}
}
#endregion
}
}

View File

@@ -160,7 +160,11 @@ namespace SqlSugar
IUpdateable<T> Updateable<T>(Expression<Func<T, T>> columns) where T : class, new();
IUpdateable<T> Updateable<T>(List<T> UpdateObjs) where T : class, new();
IUpdateable<T> Updateable<T>(T UpdateObj) where T : class, new();
IUpdateable<T> Updateable<T>(T[] UpdateObjs) where T : class, new();
IUpdateable<T> Updateable<T>(T[] UpdateObjs) where T : class, new();
#endregion
#region Cache
SugarCacheProvider DataCache { get; }
#endregion
}
}

View File

@@ -70,6 +70,7 @@
</ItemGroup>
<ItemGroup>
<Compile Include="Abstract\AopProvider\AopProvider.cs" />
<Compile Include="Abstract\CacheProvider\CacheProvider.cs" />
<Compile Include="Abstract\CodeFirstProvider\CodeFirstProvider.cs" />
<Compile Include="Abstract\AdoProvider\AdoAccessory.cs" />
<Compile Include="Abstract\DbBindProvider\DbBindAccessory.cs" />

View File

@@ -718,6 +718,13 @@ namespace SqlSugar
#endregion
#region Cache
public SugarCacheProvider DataCache
{
get { return this.Context.DataCache; }
}
#endregion
#region Other method
public DateTime GetDate()
{