private void NFileCache_MaxCacheSizeReached(object sender, FileCacheEventArgs e) { // Shrink the cache to 75% of the max size // that way there's room for it to grow a bit // before we have to do this again. Trim((long)(MaxCacheSize * 0.75)); }
private void MaxCacheSizeReached(object sender, FileCacheEventArgs e) { //first try removing all non-completed items foreach (var odds in _cache.GetKeys() .Select(key => _cache.GetCacheItem(key)) .Select(item => item.Value) .OfType<TexasHoldemOdds>() .Where(odds => !odds.Completed)) { try { _cache.Remove(odds.GetCacheKey()); } catch { } } //if that has bought us some space if (_cache.GetCacheSize() < e.CurrentCacheSize) { //bail return; } //final last ditch approach //remove everything, and re-prime the cache _cache.Flush(); PrimeCache(); }
private void FileCache_MaxCacheSizeReached(object sender, FileCacheEventArgs e) { Task.Factory.StartNew((Action)(() => { // Shrink the cache to 75% of the max size // that way there's room for it to grow a bit // before we have to do this again. long newSize = ShrinkCacheToSize((long)(MaxCacheSize * 0.75)); })); }