let expiringcache and expiringkey also have expire update on containskey

This commit is contained in:
UbitUmarov
2020-08-17 15:51:48 +01:00
parent 6dcb4ed7a0
commit 1b9cdbbe40
2 changed files with 92 additions and 0 deletions

View File

@@ -295,6 +295,55 @@ namespace OpenSim.Framework
}
}
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
public bool Contains(TKey1 key, int expireMS)
{
return ContainsKey(key, expireMS);
}
public bool ContainsKey(TKey1 key, int expireMS)
{
bool gotLock = false;
try
{
try { }
finally
{
m_rwLock.EnterUpgradeableReadLock();
gotLock = true;
}
if(m_expireControl.ContainsKey(key))
{
bool gotWriteLock = false;
try
{
try { }
finally
{
m_rwLock.EnterWriteLock();
gotWriteLock = true;
}
expireMS = (expireMS > m_expire) ? expireMS : m_expire;
int now = (int)(Util.GetTimeStampMS() - m_startTS) + expireMS;
m_expireControl[key] = now;
return true;
}
finally
{
if (gotWriteLock)
m_rwLock.ExitWriteLock();
}
}
return false;
}
finally
{
if (gotLock)
m_rwLock.ExitUpgradeableReadLock();
}
}
public bool TryGetValue(TKey1 key, out TValue1 value)
{
bool success;