Files
YunTongJackYunTask/Reportapi/MyCode.Project.Infrastructure/Cache/SystemCache.cs
2025-07-04 09:50:02 +08:00

175 lines
4.7 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web;
using System.Web.Caching;
using System.Collections;
namespace MyCode.Project.Infrastructure.Cache
{
public class SystemCache:IMyCodeCacheService
{
private static System.Web.Caching.Cache cache;
public SystemCache() {
if (cache == null)
{
cache = HttpRuntime.Cache;
}
}
#region Set()
public void Set(string key, object cache_object, TimeSpan? cacheTime = null) {
if (cacheTime == null || cacheTime.Value == TimeSpan.Zero) { cacheTime = new TimeSpan(0, 0, 30); }
//相对时间过期
//cache.Insert(key,cache_object,null, System.Web.Caching.Cache.NoAbsoluteExpiration,expiration,priority,null);
//绝对时间过期
//cache.Insert(key, cache_object, null,DateTime.Now.addti,expiration, System.Web.Caching.Cache.NoSlidingExpiration);
//var second = expiration.TotalSeconds;
if (cache_object == null) { return; }
cache.Insert(key, cache_object, null, DateTime.Now.AddSeconds(cacheTime.Value.TotalSeconds), System.Web.Caching.Cache.NoSlidingExpiration);
}
#endregion
#region Get(key得到缓存值)
public object Get(string key) {
return cache.Get(key);
}
#endregion
#region Get()
public T Get<T>(string key)
{
var obj = Get(key);
return (T)obj;
}
#endregion
#region Delete(Key删除)
public void Delete(string key) {
if (Exists(key)) {
cache.Remove(key);
}
}
#endregion
#region Exists()
public bool Exists(string key)
{
if (cache[key] != null)
{
return true;
}
else {
return false;
}
}
#endregion
#region GetCacheKeys(Key)
public List<string> GetCacheKeys()
{
List<string> keys = new List<string>();
IDictionaryEnumerator ca = cache.GetEnumerator();
while (ca.MoveNext())
{
keys.Add(ca.Key.ToString());
}
return keys;
}
#endregion
#region Push()
/// <summary>
/// 放入队列
/// </summary>
/// <param name="key"></param>
/// <param name="data"></param>
public void Push(string key, object data)
{
throw new NotImplementedException();
}
#endregion
#region ListLen()
/// <summary>
/// 返回列表长度
/// </summary>
/// <param name="key"></param>
/// <returns></returns>
public long ListLen(string key)
{
throw new NotImplementedException();
}
#endregion
#region Popup()
/// <summary>
/// Popup(获取第一条数据,并删除)
/// </summary>
/// <param name="key"></param>
/// <returns></returns>
public object Popup(string key)
{
throw new NotImplementedException();
}
#endregion
#region GetNewId(id)
/// <summary>
/// 得到新的id
/// </summary>
/// <param name="key"></param>
/// <returns></returns>
public long GetNewId()
{
throw new NotImplementedException();
}
#endregion
#region Incr(1)
/// <summary>
/// 自增1返回自增后的值
/// </summary>
/// <param name="key"></param>
/// <returns></returns>
public long Incr(string key,long value = 1)
{
throw new NotImplementedException();
}
#endregion
#region SetIncr()
/// <summary>
/// 初始化原子性的功能
/// </summary>
/// <param name="key"></param>
/// <param name="data"></param>
public void SetIncr(string key, long data)
{
throw new NotImplementedException();
}
#endregion
#region GetIncr(Incr值)
/// <summary>
/// 得到Incr值
/// </summary>
/// <param name="key"></param>
/// <returns></returns>
public object GetIncr(string key)
{
throw new NotImplementedException();
}
#endregion
}
}