添加项目文件。
This commit is contained in:
54
HT.Cloud.Data/SqlSugarCache/SqlSugarCache.cs
Normal file
54
HT.Cloud.Data/SqlSugarCache/SqlSugarCache.cs
Normal file
@ -0,0 +1,54 @@
|
||||
using SqlSugar;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using HT.Cloud.Code;
|
||||
|
||||
namespace HT.Cloud.DataBase
|
||||
{
|
||||
public class SqlSugarCache : ICacheService
|
||||
{
|
||||
public void Add<TV>(string key, TV value)
|
||||
{
|
||||
CacheHelper.SetBySecond(key, value);
|
||||
}
|
||||
|
||||
public void Add<TV>(string key, TV value, int cacheDurationInSeconds)
|
||||
{
|
||||
CacheHelper.SetBySecond(key, value, cacheDurationInSeconds);
|
||||
}
|
||||
|
||||
public bool ContainsKey<TV>(string key)
|
||||
{
|
||||
return CacheHelper.Exists(key);
|
||||
}
|
||||
|
||||
public TV Get<TV>(string key)
|
||||
{
|
||||
return CacheHelper.Get<TV>(key);
|
||||
}
|
||||
|
||||
public IEnumerable<string> GetAllKey<TV>()
|
||||
{
|
||||
return CacheHelper.GetAllKey<TV>();
|
||||
}
|
||||
|
||||
public TV GetOrCreate<TV>(string cacheKey, Func<TV> create, int cacheDurationInSeconds = int.MaxValue)
|
||||
{
|
||||
if (this.ContainsKey<TV>(cacheKey))
|
||||
{
|
||||
return this.Get<TV>(cacheKey);
|
||||
}
|
||||
else
|
||||
{
|
||||
var result = create();
|
||||
this.Add(cacheKey, result, cacheDurationInSeconds);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
public void Remove<TV>(string key)
|
||||
{
|
||||
CacheHelper.Remove(key);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user