/// <summary>checks to see if cache is still valid and if LifespanMgr needs to do maintenance</summary> public void CheckValidity() { // NOTE: Monitor.Enter(this) / Monitor.Exit(this) is the same as lock(this)... We are using Monitor.TryEnter() because it // does not wait for a lock, if lock is currently held then skip and let next Touch perform cleanup. if (RequiresCleanup && Monitor.TryEnter(syncObject)) { try { if (RequiresCleanup) { // if cache is no longer valid throw contents away and start over, else cleanup old items if ((CurrentBagIndex > 1000000) || ((ValidateCache != null) && !ValidateCache())) { owner.Clear(); } else { CleanUp(getNow()); } } } finally { Monitor.Exit(syncObject); } } }
/// <summary>checks to see if cache is still valid and if LifespanMgr needs to do maintenance</summary> public void CheckValidity() { DateTime now = getNow(); // Note: Monitor.Enter(this) / Monitor.Exit(this) is the same as lock(this)... We are using Monitor.TryEnter() because it // does not wait for a lock, if lock is currently held then skip and let next Touch perform cleanup. if (((itemsInCurrentBag > bagItemLimit) || (now > nextValidityCheck)) && Monitor.TryEnter(this)) { try { if ((itemsInCurrentBag > bagItemLimit) || (now > nextValidityCheck)) { // if cache is no longer valid throw contents away and start over, else cleanup old items if ((currentBagIndex > 1000000) || ((ValidateCache != null) && !ValidateCache())) { owner.Clear(); } else { CleanUp(now); } } } finally { Monitor.Exit(this); } } }