This commit is contained in:
sunkaixuan
2017-09-29 14:53:58 +08:00
parent 6d4226d1fa
commit fb723127a0
5 changed files with 21 additions and 10 deletions

View File

@@ -7,12 +7,12 @@ namespace SqlSugar
{
internal class CacheEngines
{
public string GetCacheMapping()
public static string GetCacheMapping(CacheKey key)
{
return null;
}
public string GetCacheData()
public static string GetCacheData(string key)
{
return null;
}

View File

@@ -8,11 +8,23 @@ namespace SqlSugar
internal class CacheSchemeMain
{
public static T GetOrCreate<T>(ICacheService cacheService,QueryBuilder queryBuilder,Func<T> getData,int cacheDurationInSeconds, SqlSugarClient context)
public static T GetOrCreate<T>(ICacheService cacheService, QueryBuilder queryBuilder, Func<T> getData, int cacheDurationInSeconds, SqlSugarClient context)
{
string key = CacheKeyBuider.GetKey(context,queryBuilder).ToString();
var result= cacheService.GetOrCreate(key, () => getData(), cacheDurationInSeconds);
CacheKey key = CacheKeyBuider.GetKey(context, queryBuilder);
var mappingKey = CacheEngines.GetCacheMapping(key);
T result = default(T);
if (mappingKey.IsNullOrEmpty())
result = getData();
else
{
result = cacheService.GetOrCreate("", () => getData(), cacheDurationInSeconds);
}
return result;
}
public static void RemoveCache(string tableName)
{
}
}
}

View File

@@ -7,8 +7,7 @@ namespace SqlSugar
{
public class CacheKey
{
public new string ToString() {
return "";
}
public string[] Tables { get; set; }
public List<string> IdentificationList { get; set; }
}
}

View File

@@ -11,6 +11,6 @@ namespace SqlSugar
V Get<V>(string key);
IEnumerable<string> GetAllKey<V>();
void Remove<V>(string key);
V GetOrCreate<V>(string cacheKey, Func<V> create,int cacheDurationInSeconds);
V GetOrCreate<V>(string cacheKey, Func<V> create,int cacheDurationInSeconds=int.MaxValue);
}
}

View File

@@ -32,7 +32,7 @@ namespace SqlSugar
return ReflectionInoCore<V>.GetInstance().GetAllKey();
}
public V GetOrCreate<V>(string cacheKey, Func<V> create)
public V GetOrCreate<V>(string cacheKey, Func<V> create,int cacheDurationInSeconds=int.MaxValue)
{
return ReflectionInoCore<V>.GetInstance().GetOrCreate(cacheKey, create);
}