mirror of
http://git.coreshop.cn/jianweie/coreshoppro.git
synced 2025-12-06 19:43:26 +08:00
【新增】新增【EasyCaching.CSRedis】redis组件,替换SqlSugar二级缓存的【StackExchange.Redis】组件实现,使用异步替代同步处理二级缓存,解决【StackExchange.Redis】超过200并发后的异常情况。异步提升二级缓存获取效率。
【新增】appsetting.json配置文件增加【AppPcUrl】PC端访问地址,【AppH5Url】H5端访问地址,方便对接pc端、h5端、微信公众号端。
This commit is contained in:
58
CoreCms.Net.Caching/SqlSugar/SqlSugarCache.cs
Normal file
58
CoreCms.Net.Caching/SqlSugar/SqlSugarCache.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user