58 lines
1.5 KiB
C#
58 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 SignContacts
|
|
{
|
|
public class Common
|
|
{
|
|
/// <summary>
|
|
/// 缓存是否存在
|
|
/// </summary>
|
|
/// <param name="robotname"></param>
|
|
/// <param name="username"></param>
|
|
/// <param name="text"></param>
|
|
/// <returns></returns>
|
|
public static bool GetCache(string text)
|
|
{
|
|
try
|
|
{
|
|
Cache cache = HttpRuntime.Cache;
|
|
object item = cache[text];
|
|
return item != null ? true : false;
|
|
}
|
|
catch (Exception)
|
|
{ }
|
|
return false;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 设置缓存(辅助输入)
|
|
/// </summary>
|
|
/// <param name="robotname"></param>
|
|
/// <param name="username"></param>
|
|
/// <param name="text"></param>
|
|
/// <returns></returns>
|
|
public static bool SetCache(string text)
|
|
{
|
|
try
|
|
{
|
|
Cache cache = HttpRuntime.Cache;
|
|
//查找 md5 的缓存,不存在则返回null
|
|
object item = cache[text];
|
|
if (item == null)
|
|
cache.Insert(text, 1, null, DateTime.Now.AddMinutes(1), Cache.NoSlidingExpiration);
|
|
return true;
|
|
}
|
|
catch (Exception ex)
|
|
{ }
|
|
return false;
|
|
}
|
|
|
|
}
|
|
}
|