This commit is contained in:
454313500@qq.com
2021-05-13 01:39:34 +08:00
parent 2e5b991db0
commit fe850bbc2c
53 changed files with 1318 additions and 404 deletions

View File

@@ -0,0 +1,51 @@
using Autofac;
using Microsoft.AspNetCore.Http;
using System;
using System.Collections.Generic;
using System.Text;
namespace CC.Yi.Common.Cache
{
public class CacheHelper
{
public static ICacheWriter CacheWriter { get; set; }
static CacheHelper()
{
CacheHelper.CacheWriter = new RedisCache();
}
public bool AddCache<T>(string key, T value, DateTime expDate)
{
return CacheWriter.AddCache<T>(key,value,expDate);
}
public bool AddCache<T>(string key, T value)
{
return CacheWriter.AddCache<T>(key, value);
}
public bool RemoveCache(string key)
{
return CacheWriter.RemoveCache(key);
}
public T GetCache<T>(string key)
{
return CacheWriter.GetCache<T>(key);
}
public bool SetCache<T>(string key, T value, DateTime expDate)
{
return CacheWriter.SetCache<T>(key,value,expDate);
}
public bool SetCache<T>(string key, T value)
{
return CacheWriter.SetCache<T>(key, value);
}
}
}

View File

@@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CC.Yi.Common.Cache
{
public interface ICacheWriter
{
bool AddCache<T>(string key, T value, DateTime expDate);
bool AddCache<T>(string key, T value);
bool RemoveCache(string key);
T GetCache<T>(string key);
bool SetCache<T>(string key, T value, DateTime expDate);
bool SetCache<T>(string key, T value);
}
}

View File

@@ -0,0 +1,46 @@
using ServiceStack.Redis;
using System;
using System.Collections.Generic;
using System.Text;
namespace CC.Yi.Common.Cache
{
public class RedisCache : ICacheWriter
{
private RedisClient client;
public RedisCache()
{
client = new RedisClient("127.0.0.1", 6379, "52013142020.");
}
public bool AddCache<T>(string key, T value, DateTime expDate)
{
return client.Add<T>(key, value, expDate);
}
public bool AddCache<T>(string key, T value)
{
return client.Add<T>(key, value);
}
public bool RemoveCache(string key)
{
return client.Remove(key);
}
public T GetCache<T>(string key)
{
return client.Get<T>(key);
}
public bool SetCache<T>(string key,T value, DateTime expDate)
{
return client.Set<T>(key, value, expDate);
}
public bool SetCache<T>(string key, T value)
{
return client.Set<T>(key, value);
}
}
}