【新增】新增【EasyCaching.CSRedis】redis组件,替换SqlSugar二级缓存的【StackExchange.Redis】组件实现,使用异步替代同步处理二级缓存,解决【StackExchange.Redis】超过200并发后的异常情况。异步提升二级缓存获取效率。

【新增】appsetting.json配置文件增加【AppPcUrl】PC端访问地址,【AppH5Url】H5端访问地址,方便对接pc端、h5端、微信公众号端。
This commit is contained in:
大灰灰
2022-12-30 04:21:40 +08:00
parent 8b03f565f0
commit 2a0c5710b2
14 changed files with 237 additions and 356 deletions

View File

@@ -0,0 +1,58 @@
using CoreCms.Net.Utility;
using EasyCaching.Core;
using SqlSugar;
using System;
using System.Collections.Generic;
namespace CoreCms.Net.Caching.SqlSugar
{
/// <summary>
/// 仅供ORM缓存使用
/// </summary>
public class SqlSugarCache : ICacheService
{
private static readonly IEasyCachingProvider cache = Storage.GetService<IEasyCachingProvider>();
public void Add<V>(string key, V value)
{
cache.Set(key, value, TimeSpan.FromSeconds(int.MaxValue));
}
public void Add<V>(string key, V value, int cacheDurationInSeconds)
{
cache.Set(key, value, TimeSpan.FromSeconds(cacheDurationInSeconds));
}
public bool ContainsKey<V>(string key)
{
return cache.Exists(key);
}
public V Get<V>(string key)
{
return cache.Get<V>(key).Value;
}
public IEnumerable<string> GetAllKey<V>()
{
return cache.GetByPrefix<object>("SqlSugarDataCache.").Keys;
}
public void Remove<V>(string key)
{
cache.Remove(key);
}
public V GetOrCreate<V>(string cacheKey, Func<V> create, int cacheDurationInSeconds = 2147483647)
{
if (cache.Exists(cacheKey))
{
return cache.Get<V>(cacheKey).Value;
}
V v = create();
cache.Set(cacheKey, v, TimeSpan.FromSeconds(cacheDurationInSeconds));
return v;
}
}
}