mirror of
https://gitee.com/ccnetcore/Yi
synced 2026-03-20 00:16:37 +08:00
增加缓存AOP切面
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Yi.Framework.Common.Attribute
|
||||
{
|
||||
[AttributeUsage(AttributeTargets.Method, Inherited = true)]
|
||||
public class CachingAttribute : System.Attribute
|
||||
{
|
||||
/// <summary>
|
||||
/// 缓存绝对过期时间(分钟)
|
||||
/// </summary>
|
||||
public int AbsoluteExpiration { get; set; } = 30;
|
||||
|
||||
}
|
||||
}
|
||||
@@ -110,6 +110,11 @@ namespace Yi.Framework.Common.Base
|
||||
|
||||
}
|
||||
|
||||
public static string TryStringNull(this object value)
|
||||
{
|
||||
return value == null ? "" : value.ToString().Trim();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Object类型无值判断
|
||||
/// </summary>
|
||||
|
||||
@@ -47,6 +47,63 @@ namespace Yi.Framework.Common.Helper
|
||||
|
||||
return ConvertEx.ToUrlBase64String(bRet);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 16位MD5加密
|
||||
/// </summary>
|
||||
/// <param name="password"></param>
|
||||
/// <returns></returns>
|
||||
public static string MD5Encrypt16(string password)
|
||||
{
|
||||
var md5 = MD5.Create();
|
||||
string t2 = BitConverter.ToString(md5.ComputeHash(Encoding.Default.GetBytes(password)), 4, 8);
|
||||
t2 = t2.Replace("-", string.Empty);
|
||||
return t2;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 32位MD5加密
|
||||
/// </summary>
|
||||
/// <param name="password"></param>
|
||||
/// <returns></returns>
|
||||
public static string MD5Encrypt32(string password = "")
|
||||
{
|
||||
string pwd = string.Empty;
|
||||
try
|
||||
{
|
||||
if (!string.IsNullOrEmpty(password) && !string.IsNullOrWhiteSpace(password))
|
||||
{
|
||||
MD5 md5 = MD5.Create(); //实例化一个md5对像
|
||||
// 加密后是一个字节类型的数组,这里要注意编码UTF8/Unicode等的选择
|
||||
byte[] s = md5.ComputeHash(Encoding.UTF8.GetBytes(password));
|
||||
// 通过使用循环,将字节类型的数组转换为字符串,此字符串是常规字符格式化所得
|
||||
foreach (var item in s)
|
||||
{
|
||||
// 将得到的字符串使用十六进制类型格式。格式后的字符是小写的字母,如果使用大写(X)则格式后的字符是大写字符
|
||||
pwd = string.Concat(pwd, item.ToString("X2"));
|
||||
}
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
throw new Exception($"错误的 password 字符串:【{password}】");
|
||||
}
|
||||
return pwd;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 64位MD5加密
|
||||
/// </summary>
|
||||
/// <param name="password"></param>
|
||||
/// <returns></returns>
|
||||
public static string MD5Encrypt64(string password)
|
||||
{
|
||||
// 实例化一个md5对像
|
||||
// 加密后是一个字节类型的数组,这里要注意编码UTF8/Unicode等的选择
|
||||
MD5 md5 = MD5.Create();
|
||||
byte[] s = md5.ComputeHash(Encoding.UTF8.GetBytes(password));
|
||||
return Convert.ToBase64String(s);
|
||||
}
|
||||
}
|
||||
public class ConvertEx
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user