Commit ac91d71f authored by 黄奎's avatar 黄奎

新增缓存

parent ac0ca2db
......@@ -10,5 +10,7 @@ namespace EduSpider.Cache
/// 用户登录缓存Key
/// </summary>
public static string User_Login_Key = "JJSW_Login_";
public static string ClassIn_Cookie_Key = "ClassInCookie";
}
}
......@@ -40,6 +40,44 @@ namespace EduSpider.Cache.User
}
}
/// <summary>
/// 设置Class登录Cookie
/// </summary>
/// <param name="cacheKey"></param>
/// <param name="model"></param>
/// <param name="JwtExpirTime"></param>
public static void ClassInCookieSet(string cacheKey, ClassInTokenItem model, int JwtExpirTime)
{
try
{
TimeSpan ts = GetExpirTime(JwtExpirTime);
redis.StringSet<ClassInTokenItem>(cacheKey, model, ts);
}
catch (Exception ex)
{
LogHelper.WriteError("ClassInCookieSet", "缓存设置失败", ex);
}
}
/// <summary>
/// 获取ClassInToken
/// </summary>
/// <param name="cacheKey"></param>
/// <returns></returns>
public static ClassInTokenItem GetClassInCookie(string cacheKey)
{
ClassInTokenItem tokenInfo = new ClassInTokenItem();
try
{
tokenInfo = redis.StringGet<ClassInTokenItem>(cacheKey);
}
catch (Exception ex)
{
LogHelper.WriteError("GetUserLoginInfo", "获取缓存失败", ex);
}
return tokenInfo;
}
/// <summary>
/// 获取缓存时长
/// </summary>
......@@ -81,6 +119,8 @@ namespace EduSpider.Cache.User
}
}
/// <summary>
/// 获取缓存
/// </summary>
......@@ -92,12 +132,13 @@ namespace EduSpider.Cache.User
object info = redis.StringGet<object>(cacheKey);
return info;
}
catch (Exception)
catch (Exception ex)
{
return "";
}
}
/// <summary>
/// 账号仓储层对象
/// </summary>
......@@ -160,4 +201,9 @@ namespace EduSpider.Cache.User
}
}
public class ClassInTokenItem
{
public string CacheCookies { get; set; }
}
}
\ No newline at end of file
......@@ -49,6 +49,7 @@
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\EduSpider.Cache\EduSpider.Cache.csproj" />
<ProjectReference Include="..\EduSpider.IRepository\EduSpider.IRepository.csproj" />
<ProjectReference Include="..\EduSpider.Model\EduSpider.Model.csproj" />
<ProjectReference Include="..\EduSpider.Repository\EduSpider.Repository.csproj" />
......
......@@ -18,7 +18,21 @@ namespace TicketSpider.Spiders.ClassInRule
if (string.IsNullOrEmpty(loginCookies))
{
ClassInAccountManager.ClearCookie();
string key = EduSpider.Cache.CacheKey.ClassIn_Cookie_Key;
int ExpirTime = 60 * 60 * 12;
var cacheCookie = EduSpider.Cache.User.UserReidsCache.GetClassInCookie(key);
if (cacheCookie != null && !string.IsNullOrEmpty(cacheCookie.CacheCookies.ToString()))
{
loginCookies = cacheCookie.CacheCookies;
}
else
{
loginCookies = ClassInAccountManager.GetInstance();
if (!string.IsNullOrEmpty(loginCookies))
{
EduSpider.Cache.User.UserReidsCache.ClassInCookieSet(key, new EduSpider.Cache.User.ClassInTokenItem() { CacheCookies=loginCookies}, ExpirTime);
}
}
}
InfoHelper.WriteLine("cookies:" + loginCookies);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment