mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-12-26 14:15:50 +08:00
Add db.DataCache
This commit is contained in:
43
Src/Asp.Net/SqlSugar/Abstract/CacheProvider/CacheProvider.cs
Normal file
43
Src/Asp.Net/SqlSugar/Abstract/CacheProvider/CacheProvider.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
@@ -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" />
|
||||
|
||||
@@ -718,6 +718,13 @@ namespace SqlSugar
|
||||
|
||||
#endregion
|
||||
|
||||
#region Cache
|
||||
public SugarCacheProvider DataCache
|
||||
{
|
||||
get { return this.Context.DataCache; }
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Other method
|
||||
public DateTime GetDate()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user