public object Get (string key)
{
try {
cacheLock.EnterUpgradeableReadLock ();
CacheItem it = cache [key];
if (it == null)
return null;
if (it.Dependency != null && it.Dependency.HasChanged) {
try {
cacheLock.EnterWriteLock ();
if (!NeedsUpdate (it, CacheItemUpdateReason.DependencyChanged, false))
Remove (it.Key, CacheItemRemovedReason.DependencyChanged, false, true);
} finally {
// See comment at the top of the file, above cacheLock declaration
cacheLock.ExitWriteLock ();
}
return null;
}
if (!DisableExpiration) {
if (it.SlidingExpiration != NoSlidingExpiration) {
it.AbsoluteExpiration = DateTime.Now + it.SlidingExpiration;
// Cast to long is ok since we know that sliding expiration
// is less than 365 days (31536000000ms)
long remaining = (long)it.SlidingExpiration.TotalMilliseconds;
it.ExpiresAt = it.AbsoluteExpiration.Ticks;
if (expirationTimer != null && (expirationTimerPeriod == 0 || expirationTimerPeriod > remaining)) {
expirationTimerPeriod = remaining;
expirationTimer.Change (expirationTimerPeriod, expirationTimerPeriod);
}
} else if (DateTime.Now >= it.AbsoluteExpiration) {
try {
cacheLock.EnterWriteLock ();
if (!NeedsUpdate (it, CacheItemUpdateReason.Expired, false))
Remove (key, CacheItemRemovedReason.Expired, false, true);
} finally {
// See comment at the top of the file, above cacheLock declaration
cacheLock.ExitWriteLock ();
}
return null;
}
}
return it.Value;
} finally {
// See comment at the top of the file, above cacheLock declaration
cacheLock.ExitUpgradeableReadLock ();
}
}