init
This commit is contained in:
commit
e124a47765
19374 changed files with 9806149 additions and 0 deletions
61
Framework/Caching/LoginInfoCache.cs
Normal file
61
Framework/Caching/LoginInfoCache.cs
Normal file
|
@ -0,0 +1,61 @@
|
|||
using System;
|
||||
using CacheManager.Core;
|
||||
using CacheManager.Core.Internal;
|
||||
using Kreta.Framework.Security;
|
||||
|
||||
namespace Kreta.Framework.Caching
|
||||
{
|
||||
public sealed class LoginInfoCache : GenericCache<LoginInfo>
|
||||
{
|
||||
private static readonly string LoginInfoCacheKeyPrefix = $"{nameof(Kreta)}_{nameof(LoginInfoCache)}_";
|
||||
|
||||
private static string GetCacheKey(string sessionId)
|
||||
{
|
||||
return $"{LoginInfoCacheKeyPrefix}{sessionId}";
|
||||
}
|
||||
|
||||
public LoginInfoCache(CacheManager cacheManager) : base(cacheManager, nameof(LoginInfoCache))
|
||||
{
|
||||
}
|
||||
|
||||
public int SessionTimeout { get; set; }
|
||||
|
||||
public void PutLoginInfo(LoginInfo loginInfo)
|
||||
{
|
||||
Put(GetCacheKey(loginInfo.SessionID), loginInfo);
|
||||
}
|
||||
|
||||
public void UpdateLoginInfo(LoginInfo loginInfo)
|
||||
{
|
||||
Update(GetCacheKey(loginInfo.SessionID), _ => loginInfo);
|
||||
}
|
||||
|
||||
public void RemoveLoginInfo(string sessionId)
|
||||
{
|
||||
Remove(GetCacheKey(sessionId));
|
||||
}
|
||||
|
||||
protected override void Cache_OnRemoveByHandle(object sender, CacheItemRemovedEventArgs e)
|
||||
{
|
||||
if (e.Key.StartsWith(LoginInfoCacheKeyPrefix, StringComparison.Ordinal) && e.Reason == CacheItemRemovedReason.Expired)
|
||||
{
|
||||
SDAServer.Instance.SessionManager.DeleteSession((LoginInfo)e.Value);
|
||||
}
|
||||
}
|
||||
|
||||
public LoginInfo GetLoginInfo(string sessionId)
|
||||
{
|
||||
return Get(GetCacheKey(sessionId));
|
||||
}
|
||||
|
||||
public bool IsExistsLoginInfo(string sessionId)
|
||||
{
|
||||
return Exists(GetCacheKey(sessionId));
|
||||
}
|
||||
|
||||
public void Ping(string sessionId)
|
||||
{
|
||||
Expire(GetCacheKey(sessionId), ExpirationMode.Sliding, new TimeSpan(0, SessionTimeout, 0));
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue