增加清除缓存
This commit is contained in:
parent
37a7c95ada
commit
0c95613ed4
|
|
@ -17,8 +17,19 @@ namespace HuanMeng.MiaoYu.Code.Cache
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public abstract class CommonDataEntityCache<T>(object lockObj, int cacheTime = 36000) : ICacheClearData, ICacheReloadData where T : class
|
public abstract class CommonDataEntityCache<T> : ICacheClearData, ICacheReloadData where T : class
|
||||||
{
|
{
|
||||||
|
//(object lockObj, int cacheTime = 36000)
|
||||||
|
protected object lockObj;
|
||||||
|
protected int cacheTime;
|
||||||
|
|
||||||
|
protected CommonDataEntityCache(object lockObj, int cacheTime = 36000)
|
||||||
|
{
|
||||||
|
this.lockObj = lockObj;
|
||||||
|
this.cacheTime = cacheTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
|
||||||
|
|
@ -2,9 +2,13 @@
|
||||||
|
|
||||||
using AutoMapper;
|
using AutoMapper;
|
||||||
|
|
||||||
|
using HuanMeng.MiaoYu.Code.Cache.Contract;
|
||||||
using HuanMeng.MiaoYu.Code.Cache.Special;
|
using HuanMeng.MiaoYu.Code.Cache.Special;
|
||||||
|
using HuanMeng.MiaoYu.Code.DataAccess;
|
||||||
using HuanMeng.MiaoYu.Model.Dto.Character;
|
using HuanMeng.MiaoYu.Model.Dto.Character;
|
||||||
|
|
||||||
|
using System.Linq.Expressions;
|
||||||
|
|
||||||
namespace HuanMeng.MiaoYu.Code.Cache
|
namespace HuanMeng.MiaoYu.Code.Cache
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
@ -217,7 +221,7 @@ namespace HuanMeng.MiaoYu.Code.Cache
|
||||||
object cacheLock;
|
object cacheLock;
|
||||||
if (!CacheLockList.TryGetValue(typeof(T), out cacheLock))
|
if (!CacheLockList.TryGetValue(typeof(T), out cacheLock))
|
||||||
{
|
{
|
||||||
Console.WriteLine("没有找到锁对象==>"+typeof(T).Name);
|
Console.WriteLine("没有找到锁对象==>" + typeof(T).Name);
|
||||||
// 创建一个新的锁对象,并添加到 CacheLockList 中
|
// 创建一个新的锁对象,并添加到 CacheLockList 中
|
||||||
cacheLock = new object();
|
cacheLock = new object();
|
||||||
CacheLockList[typeof(T)] = cacheLock;
|
CacheLockList[typeof(T)] = cacheLock;
|
||||||
|
|
@ -235,6 +239,27 @@ namespace HuanMeng.MiaoYu.Code.Cache
|
||||||
var cache = GetMiaoYuDataEntityCache<T>(dao);
|
var cache = GetMiaoYuDataEntityCache<T>(dao);
|
||||||
return cache?.DataList ?? new List<T>();
|
return cache?.DataList ?? new List<T>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 清除全部缓存
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="dao"></param>
|
||||||
|
public static void ClareMiaoYuDataEntityCache(DAO dao)
|
||||||
|
{
|
||||||
|
foreach (var item in CacheLockList)
|
||||||
|
{
|
||||||
|
var t = item.Key;
|
||||||
|
Type cacheType = typeof(MiaoYuDataEntityCache<>).MakeGenericType(t);
|
||||||
|
var shujuduixiang = Activator.CreateInstance(cacheType, dao, item.Value,36000);
|
||||||
|
var x = shujuduixiang as ICacheClearData;
|
||||||
|
if (x != null)
|
||||||
|
{
|
||||||
|
x.ClearData();
|
||||||
|
}
|
||||||
|
//new MiaoYuDataEntityCache<T>(dao, cacheLock);
|
||||||
|
//Activator.CreateInstance(t);
|
||||||
|
}
|
||||||
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region 图片扩展
|
#region 图片扩展
|
||||||
|
|
|
||||||
27
src/0-core/HuanMeng.MiaoYu.Code/Other/OtherBLL.cs
Normal file
27
src/0-core/HuanMeng.MiaoYu.Code/Other/OtherBLL.cs
Normal file
|
|
@ -0,0 +1,27 @@
|
||||||
|
using HuanMeng.MiaoYu.Code.Cache;
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace HuanMeng.MiaoYu.Code.Other
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 杂项
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="serviceProvider"></param>
|
||||||
|
public class OtherBLL(IServiceProvider serviceProvider) : MiaoYuBase(serviceProvider)
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 清除缓存
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
public Task CleraCache()
|
||||||
|
{
|
||||||
|
MiaoYuCacheExtend.ClareMiaoYuDataEntityCache(Dao);
|
||||||
|
return Task.CompletedTask;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,30 @@
|
||||||
|
using HuanMeng.MiaoYu.Code.Other;
|
||||||
|
using HuanMeng.MiaoYu.WebApi.Base;
|
||||||
|
|
||||||
|
using Microsoft.AspNetCore.Authorization;
|
||||||
|
using Microsoft.AspNetCore.Http;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
|
||||||
|
namespace HuanMeng.MiaoYu.WebApi.Controllers
|
||||||
|
{
|
||||||
|
[Route("api/[controller]")]
|
||||||
|
[ApiController]
|
||||||
|
public class OtherController : MiaoYuControllerBase
|
||||||
|
{
|
||||||
|
public OtherController(IServiceProvider _serviceProvider) : base(_serviceProvider)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// 清除缓存
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
[HttpGet("cache/clear")]
|
||||||
|
[AllowAnonymous]
|
||||||
|
public async Task Clear()
|
||||||
|
{
|
||||||
|
OtherBLL otherBLL = new OtherBLL(ServiceProvider);
|
||||||
|
await otherBLL.CleraCache();
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user