54 lines
1.5 KiB
C#
54 lines
1.5 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Web;
|
|
using System.Web.Caching;
|
|
|
|
namespace DYRebate
|
|
{
|
|
public class Comm
|
|
{
|
|
|
|
public static bool SetCache(string key, string value, int seconds = 180)
|
|
{
|
|
try
|
|
{
|
|
var MD5 = CsharpHttpHelper.HttpExtend.GetMD5String($"{key}");
|
|
Cache cache = HttpRuntime.Cache;
|
|
//查找 md5 的缓存,不存在则返回null
|
|
object item = cache[MD5];
|
|
if (item == null)
|
|
cache.Insert(MD5, value, null, DateTime.Now.AddSeconds(seconds), System.Web.Caching.Cache.NoSlidingExpiration);
|
|
return true;
|
|
}
|
|
catch (Exception ex)
|
|
{ }
|
|
return false;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取缓存数据
|
|
/// </summary>
|
|
/// <param name="robotname"></param>
|
|
/// <param name="username"></param>
|
|
/// <param name="text"></param>
|
|
/// <returns></returns>
|
|
public static string GetCache(string key)
|
|
{
|
|
try
|
|
{
|
|
var MD5 = CsharpHttpHelper.HttpExtend.GetMD5String($"{key}");
|
|
Cache cache = HttpRuntime.Cache;
|
|
object item = cache[MD5];
|
|
return item?.ToString();
|
|
}
|
|
catch (Exception)
|
|
{ }
|
|
return null;
|
|
}
|
|
|
|
}
|
|
}
|