mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-06-28 13:34:32 +08:00
CodeFirst DbFirst Cache BUG
This commit is contained in:
parent
9f34948ed1
commit
bdf758c16f
@ -22,6 +22,7 @@ namespace SqlSugar
|
||||
}
|
||||
public virtual void InitTables(Type entityType)
|
||||
{
|
||||
this.Context.RewritableMethods.RemoveCacheAll();
|
||||
if (!this.Context.DbMaintenance.IsAnySystemTablePermissions())
|
||||
{
|
||||
Check.Exception(true, "Dbfirst and Codefirst requires system table permissions");
|
||||
|
@ -39,6 +39,7 @@ namespace SqlSugar
|
||||
|
||||
public void Init()
|
||||
{
|
||||
this.Context.RewritableMethods.RemoveCacheAll();
|
||||
if (!this.Context.DbMaintenance.IsAnySystemTablePermissions())
|
||||
{
|
||||
Check.Exception(true, "Dbfirst and Codefirst requires system table permissions");
|
||||
|
@ -41,7 +41,8 @@ namespace SqlSugar
|
||||
if (_instance == null)
|
||||
{
|
||||
_instance = new CacheManager<V>();
|
||||
CacheManager.Add(_instance.InstanceCache);
|
||||
Action addItem =()=> { CacheManager<V>.GetInstance().RemoveAllCache(); };
|
||||
CacheManager.Add(addItem);
|
||||
}
|
||||
return _instance;
|
||||
}
|
||||
@ -62,6 +63,14 @@ namespace SqlSugar
|
||||
this.InstanceCache.TryRemove(key, out val);
|
||||
}
|
||||
|
||||
public void RemoveAllCache()
|
||||
{
|
||||
foreach (var key in GetAllKey())
|
||||
{
|
||||
this.Remove(key);
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable<string> GetAllKey()
|
||||
{
|
||||
return this.InstanceCache.Keys;
|
||||
@ -89,19 +98,19 @@ namespace SqlSugar
|
||||
}
|
||||
public static class CacheManager
|
||||
{
|
||||
private static List<object> CacheObjects = new List<object>();
|
||||
internal static void Add(object CacheObject)
|
||||
private static List<Action> removeActions = new List<Action>();
|
||||
internal static void Add(Action removeAction)
|
||||
{
|
||||
CacheObjects.Add(CacheObject);
|
||||
removeActions.Add(removeAction);
|
||||
}
|
||||
|
||||
public static void RemoveAllCache()
|
||||
{
|
||||
lock (CacheObjects)
|
||||
lock (removeActions)
|
||||
{
|
||||
for (int i = 0; i < CacheObjects.Count; i++)
|
||||
foreach (var item in removeActions)
|
||||
{
|
||||
CacheObjects[i] = Activator.CreateInstance(CacheObjects[i].GetType(), true);
|
||||
item();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -188,6 +188,11 @@ namespace SqlSugar
|
||||
CacheManager.RemoveAllCache();
|
||||
}
|
||||
|
||||
public void RemoveCacheAll<T>()
|
||||
{
|
||||
CacheManager<T>.GetInstance().RemoveAllCache();
|
||||
}
|
||||
|
||||
public void RemoveCache<T>(string key)
|
||||
{
|
||||
CacheManager<T>.GetInstance().Remove(key);
|
||||
|
@ -17,6 +17,9 @@ namespace SqlSugar
|
||||
T TranslateCopy<T>(T sourceObject);
|
||||
dynamic DataTableToDynamic(DataTable table);
|
||||
ICacheManager<T> GetCacheInstance<T>();
|
||||
void RemoveCacheAll();
|
||||
void RemoveCacheAll<T>();
|
||||
void RemoveCache<T>(string key);
|
||||
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user