宁波既有建筑外墙脱落问卷调查
This commit is contained in:
@@ -1,33 +0,0 @@
|
||||
using Furion.ConfigurableOptions;
|
||||
|
||||
namespace Ewide.Core
|
||||
{
|
||||
/// <summary>
|
||||
/// 缓存配置
|
||||
/// </summary>
|
||||
public class CacheOptions : IConfigurableOptions
|
||||
{
|
||||
/// <summary>
|
||||
/// 缓存类型
|
||||
/// </summary>
|
||||
public CacheType CacheType { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Redis配置
|
||||
/// </summary>
|
||||
public string RedisConnectionString { get; set; }
|
||||
}
|
||||
|
||||
public enum CacheType
|
||||
{
|
||||
/// <summary>
|
||||
/// 内存缓存
|
||||
/// </summary>
|
||||
MemoryCache,
|
||||
|
||||
/// <summary>
|
||||
/// Redis缓存
|
||||
/// </summary>
|
||||
RedisCache
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Ewide.Core
|
||||
@@ -103,5 +104,10 @@ namespace Ewide.Core
|
||||
/// <param name="expire">有效期</param>
|
||||
/// <returns></returns>
|
||||
Task<bool> SetAsync(string key, object value, TimeSpan expire);
|
||||
/// <summary>
|
||||
/// 获取所有缓存
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
List<string> GetAllKeys();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -107,7 +107,7 @@ namespace Ewide.Core
|
||||
return Task.FromResult(true);
|
||||
}
|
||||
|
||||
private List<string> GetAllKeys()
|
||||
public List<string> GetAllKeys()
|
||||
{
|
||||
const BindingFlags flags = BindingFlags.Instance | BindingFlags.NonPublic;
|
||||
var entries = _memoryCache.GetType().GetField("_entries", flags).GetValue(_memoryCache);
|
||||
@@ -121,5 +121,6 @@ namespace Ewide.Core
|
||||
//}
|
||||
//return keys;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
using Furion.DependencyInjection;
|
||||
using Microsoft.Extensions.Options;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
@@ -62,6 +63,11 @@ namespace Ewide.Core
|
||||
return RedisHelper.Get<T>(key);
|
||||
}
|
||||
|
||||
public List<string> GetAllKeys()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public Task<string> GetAsync(string key)
|
||||
{
|
||||
return RedisHelper.GetAsync(key);
|
||||
|
||||
63
20220330_Vote/Ewide.Core/Cache/SqlSugarCache.cs
Normal file
63
20220330_Vote/Ewide.Core/Cache/SqlSugarCache.cs
Normal file
@@ -0,0 +1,63 @@
|
||||
using Furion;
|
||||
using SqlSugar;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Ewide.Core.Cache
|
||||
{
|
||||
|
||||
public class SqlSugarCache : ICacheService
|
||||
{
|
||||
private static ICache _cache = App.GetOptions<CacheOptions>().CacheType == CacheType.MemoryCache ? App.RootServices.GetService(typeof(MemoryCache)) as ICache : App.RootServices.GetService(typeof(RedisCache)) as ICache;
|
||||
|
||||
public void Add<TV>(string key, TV value)
|
||||
{
|
||||
_cache.Set(key, value);
|
||||
}
|
||||
|
||||
public void Add<TV>(string key, TV value, int cacheDurationInSeconds)
|
||||
{
|
||||
_cache.Set(key, value, TimeSpan.FromSeconds(cacheDurationInSeconds));
|
||||
}
|
||||
|
||||
public bool ContainsKey<TV>(string key)
|
||||
{
|
||||
return _cache.Exists(key);
|
||||
}
|
||||
|
||||
public TV Get<TV>(string key)
|
||||
{
|
||||
return _cache.Get<TV>(key);
|
||||
}
|
||||
|
||||
public IEnumerable<string> GetAllKey<TV>()
|
||||
{
|
||||
|
||||
return _cache.GetAllKeys();
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
_cache.Del(key);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user