This commit is contained in:
sunkaixuan 2017-09-28 17:25:02 +08:00
parent 3377ac62a5
commit 070315c1e5
2 changed files with 18 additions and 18 deletions

View File

@ -271,17 +271,17 @@ namespace SqlSugar
public void RemoveCacheAll() public void RemoveCacheAll()
{ {
CacheHelper.RemoveAllCache(); ReflectionInoHelper.RemoveAllCache();
} }
public void RemoveCacheAll<T>() public void RemoveCacheAll<T>()
{ {
ReflectionInoCacheHelper<T>.GetInstance().RemoveAllCache(); ReflectionInoCore<T>.GetInstance().RemoveAllCache();
} }
public void RemoveCache<T>(string key) public void RemoveCache<T>(string key)
{ {
ReflectionInoCacheHelper<T>.GetInstance().Remove(key); ReflectionInoCore<T>.GetInstance().Remove(key);
} }
#endregion #endregion

View File

@ -10,44 +10,44 @@ namespace SqlSugar
{ {
public void Add<V>(string key, V value) public void Add<V>(string key, V value)
{ {
ReflectionInoCacheHelper<V>.GetInstance().Add(key,value); ReflectionInoCore<V>.GetInstance().Add(key,value);
} }
public void Add<V>(string key, V value, int cacheDurationInSeconds) public void Add<V>(string key, V value, int cacheDurationInSeconds)
{ {
ReflectionInoCacheHelper<V>.GetInstance().Add(key, value,cacheDurationInSeconds); ReflectionInoCore<V>.GetInstance().Add(key, value,cacheDurationInSeconds);
} }
public bool ContainsKey<V>(string key) public bool ContainsKey<V>(string key)
{ {
return ReflectionInoCacheHelper<V>.GetInstance().ContainsKey(key); return ReflectionInoCore<V>.GetInstance().ContainsKey(key);
} }
public V Get<V>(string key) public V Get<V>(string key)
{ {
return ReflectionInoCacheHelper<V>.GetInstance().Get(key); return ReflectionInoCore<V>.GetInstance().Get(key);
} }
public IEnumerable<string> GetAllKey<V>() public IEnumerable<string> GetAllKey<V>()
{ {
return ReflectionInoCacheHelper<V>.GetInstance().GetAllKey(); return ReflectionInoCore<V>.GetInstance().GetAllKey();
} }
public V GetOrCreate<V>(string cacheKey, Func<V> create) public V GetOrCreate<V>(string cacheKey, Func<V> create)
{ {
return ReflectionInoCacheHelper<V>.GetInstance().GetOrCreate(cacheKey, create); return ReflectionInoCore<V>.GetInstance().GetOrCreate(cacheKey, create);
} }
public void Remove<V>(string key) public void Remove<V>(string key)
{ {
ReflectionInoCacheHelper<V>.GetInstance().Remove(key); ReflectionInoCore<V>.GetInstance().Remove(key);
} }
} }
public class ReflectionInoCacheHelper<V> public class ReflectionInoCore<V>
{ {
readonly System.Collections.Concurrent.ConcurrentDictionary<string, V> InstanceCache = new System.Collections.Concurrent.ConcurrentDictionary<string, V>(); readonly System.Collections.Concurrent.ConcurrentDictionary<string, V> InstanceCache = new System.Collections.Concurrent.ConcurrentDictionary<string, V>();
private static ReflectionInoCacheHelper<V> _instance = null; private static ReflectionInoCore<V> _instance = null;
private static readonly object _instanceLock = new object(); private static readonly object _instanceLock = new object();
private ReflectionInoCacheHelper() { } private ReflectionInoCore() { }
public V this[string key] public V this[string key]
{ {
@ -70,15 +70,15 @@ namespace SqlSugar
return default(V); return default(V);
} }
public static ReflectionInoCacheHelper<V> GetInstance() public static ReflectionInoCore<V> GetInstance()
{ {
if (_instance == null) if (_instance == null)
lock (_instanceLock) lock (_instanceLock)
if (_instance == null) if (_instance == null)
{ {
_instance = new ReflectionInoCacheHelper<V>(); _instance = new ReflectionInoCore<V>();
Action addItem =()=> { ReflectionInoCacheHelper<V>.GetInstance().RemoveAllCache(); }; Action addItem =()=> { ReflectionInoCore<V>.GetInstance().RemoveAllCache(); };
CacheHelper.AddRemoveFunc(addItem); ReflectionInoHelper.AddRemoveFunc(addItem);
} }
return _instance; return _instance;
} }
@ -123,7 +123,7 @@ namespace SqlSugar
} }
} }
} }
internal static class CacheHelper internal static class ReflectionInoHelper
{ {
private static List<Action> removeActions = new List<Action>(); private static List<Action> removeActions = new List<Action>();
internal static void AddRemoveFunc(Action removeAction) internal static void AddRemoveFunc(Action removeAction)