You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

86 lines
2.2 KiB

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Sog;
namespace Account
{
public class SnsFriendCacheOp : BaseReloadableService
{
private SnsFriendAccountInfoCache m_table;
public override int GetServiceType()
{
return AccountServiceType.SnsFriendCacheOp;
}
//销毁的时候置空
public override void Dispose()
{
m_table = null;
}
public SnsFriendCacheOp(SnsFriendAccountInfoCache cacheTable)
{
m_table = cacheTable;
}
public SnsFriendInfoAccountObj GetSnsFriendInfo(string accountKey)
{
SnsFriendInfoAccountObj value;
m_table.m_cacheTable.TryGetValue(accountKey, out value);
return value;
}
public SnsFriendInfoAccountObj AddNewSnsFriendInfo(int accountType, string accountID)
{
string accountKey = AccountUtils.CalcAccountKey(accountType, accountID);
SnsFriendInfoAccountObj value;
if(m_table.m_cacheTable.TryGetValue(accountKey, out value))
{
return value;
}
value = new SnsFriendInfoAccountObj();
value.Info.AccountType = accountType;
value.Info.AccountID.SetString(accountID);
m_table.m_cacheTable.Add(accountKey, value);
return value;
}
public bool NeedQuerySnsFriendInfoFromDB(string accountKey)
{
SnsFriendInfoAccountObj snsFriendInfoInCache = GetSnsFriendInfo(accountKey);
if(snsFriendInfoInCache == null)
{
return true;
}
//已经查询到uid了,不需要再次查询
if(snsFriendInfoInCache.Info.Uid > 0)
{
return false;
}
//否则,如果uid为0,那么一段时间后新玩家有可能来玩游戏了
//这个逻辑算是容错逻辑
if(AppTime.GetNowSysMs() > snsFriendInfoInCache.LastQueryDBTime + 3600*1000)
{
return true;
}
return false;
}
}
}